(function(factory){factory(jQuery)})(function($){var pluses=/\+/g;function encode(s){return config.raw?s:encodeURIComponent(s)}function decode(s){return config.raw?s:decodeURIComponent(s)}function stringifyCookieValue(value){return encode(config.json?JSON.stringify(value):String(value))}function parseCookieValue(s){if(s.indexOf('"')===0){s=s.slice(1,-1).replace(/\\"/g,'"').replace(/\\\\/g,"\\")}try{s=decodeURIComponent(s.replace(pluses," "));return config.json?JSON.parse(s):s}catch(e){}}function read(s,converter){var value=config.raw?s:parseCookieValue(s);return $.isFunction(converter)?converter(value):value}var config=$.cookie=function(key,value,options){if(value!==undefined&&!$.isFunction(value)){options=$.extend({},config.defaults,options);if(typeof options.expires==="number"){var days=options.expires,t=options.expires=new Date;t.setTime(+t+days*864e5)}return document.cookie=[encode(key),"=",stringifyCookieValue(value),options.expires?"; expires="+options.expires.toUTCString():"",options.path?"; path="+options.path:"",options.domain?"; domain="+options.domain:"",options.secure?"; secure":""].join("")}var result=key?undefined:{};var cookies=document.cookie?document.cookie.split("; "):[];for(var i=0,l=cookies.length;i<l;i++){var parts=cookies[i].split("=");var name=decode(parts.shift());var cookie=parts.join("=");if(key&&key===name){result=read(cookie,value);break}if(!key&&(cookie=read(cookie))!==undefined){result[name]=cookie}}return result};config.defaults={};$.removeCookie=function(key,options){if($.cookie(key)===undefined){return false}$.cookie(key,"",$.extend({},options,{expires:-1}));return!$.cookie(key)}});if(typeof jQuery==="undefined"){throw new Error("Bootstrap requires jQuery")}+function($){"use strict";function transitionEnd(){var el=document.createElement("bootstrap");var transEndEventNames={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"};for(var name in transEndEventNames){if(el.style[name]!==undefined){return{end:transEndEventNames[name]}}}}$.fn.emulateTransitionEnd=function(duration){var called=false,$el=this;$(this).one($.support.transition.end,function(){called=true});var callback=function(){if(!called)$($el).trigger($.support.transition.end)};setTimeout(callback,duration);return this};$(function(){$.support.transition=transitionEnd()})}(jQuery);+function($){"use strict";var dismiss='[data-dismiss="alert"]';var Alert=function(el){$(el).on("click",dismiss,this.close)};Alert.prototype.close=function(e){var $this=$(this);var selector=$this.attr("data-target");if(!selector){selector=$this.attr("href");selector=selector&&selector.replace(/.*(?=#[^\s]*$)/,"")}var $parent=$(selector);if(e)e.preventDefault();if(!$parent.length){$parent=$this.hasClass("alert")?$this:$this.parent()}$parent.trigger(e=$.Event("close.bs.alert"));if(e.isDefaultPrevented())return;$parent.removeClass("in");function removeElement(){$parent.trigger("closed.bs.alert").remove()}$.support.transition&&$parent.hasClass("fade")?$parent.one($.support.transition.end,removeElement).emulateTransitionEnd(150):removeElement()};var old=$.fn.alert;$.fn.alert=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.alert");if(!data)$this.data("bs.alert",data=new Alert(this));if(typeof option=="string")data[option].call($this)})};$.fn.alert.Constructor=Alert;$.fn.alert.noConflict=function(){$.fn.alert=old;return this};$(document).on("click.bs.alert.data-api",dismiss,Alert.prototype.close)}(jQuery);+function($){"use strict";var Button=function(element,options){this.$element=$(element);this.options=$.extend({},Button.DEFAULTS,options)};Button.DEFAULTS={loadingText:"loading..."};Button.prototype.setState=function(state){var d="disabled";var $el=this.$element;var val=$el.is("input")?"val":"html";var data=$el.data();state=state+"Text";if(!data.resetText)$el.data("resetText",$el[val]());$el[val](data[state]||this.options[state]);setTimeout(function(){state=="loadingText"?$el.addClass(d).attr(d,d):$el.removeClass(d).removeAttr(d)},0)};Button.prototype.toggle=function(){var $parent=this.$element.closest('[data-toggle="buttons"]');if($parent.length){var $input=this.$element.find("input").prop("checked",!this.$element.hasClass("active")).trigger("change");if($input.prop("type")==="radio")$parent.find(".active").removeClass("active")}this.$element.toggleClass("active")};var old=$.fn.button;$.fn.button=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.button");var options=typeof option=="object"&&option;if(!data)$this.data("bs.button",data=new Button(this,options));if(option=="toggle")data.toggle();else if(option)data.setState(option)})};$.fn.button.Constructor=Button;$.fn.button.noConflict=function(){$.fn.button=old;return this};$(document).on("click.bs.button.data-api","[data-toggle^=button]",function(e){var $btn=$(e.target);if(!$btn.hasClass("btn"))$btn=$btn.closest(".btn");$btn.button("toggle");e.preventDefault()})}(jQuery);+function($){"use strict";var Carousel=function(element,options){this.$element=$(element);this.$indicators=this.$element.find(".carousel-indicators");this.options=options;this.paused=this.sliding=this.interval=this.$active=this.$items=null;this.options.pause=="hover"&&this.$element.on("mouseenter",$.proxy(this.pause,this)).on("mouseleave",$.proxy(this.cycle,this))};Carousel.DEFAULTS={interval:5e3,pause:"hover",wrap:true};Carousel.prototype.cycle=function(e){e||(this.paused=false);this.interval&&clearInterval(this.interval);this.options.interval&&!this.paused&&(this.interval=setInterval($.proxy(this.next,this),this.options.interval));return this};Carousel.prototype.getActiveIndex=function(){this.$active=this.$element.find(".item.active");this.$items=this.$active.parent().children();return this.$items.index(this.$active)};Carousel.prototype.to=function(pos){var that=this;var activeIndex=this.getActiveIndex();if(pos>this.$items.length-1||pos<0)return;if(this.sliding)return this.$element.one("slid",function(){that.to(pos)});if(activeIndex==pos)return this.pause().cycle();return this.slide(pos>activeIndex?"next":"prev",$(this.$items[pos]))};Carousel.prototype.pause=function(e){e||(this.paused=true);if(this.$element.find(".next, .prev").length&&$.support.transition.end){this.$element.trigger($.support.transition.end);this.cycle(true)}this.interval=clearInterval(this.interval);return this};Carousel.prototype.next=function(){if(this.sliding)return;return this.slide("next")};Carousel.prototype.prev=function(){if(this.sliding)return;return this.slide("prev")};Carousel.prototype.slide=function(type,next){var $active=this.$element.find(".item.active");var $next=next||$active[type]();var isCycling=this.interval;var direction=type=="next"?"left":"right";var fallback=type=="next"?"first":"last";var that=this;if(!$next.length){if(!this.options.wrap)return;$next=this.$element.find(".item")[fallback]()}this.sliding=true;isCycling&&this.pause();var e=$.Event("slide.bs.carousel",{relatedTarget:$next[0],direction:direction});if($next.hasClass("active"))return;if(this.$indicators.length){this.$indicators.find(".active").removeClass("active");this.$element.one("slid",function(){var $nextIndicator=$(that.$indicators.children()[that.getActiveIndex()]);$nextIndicator&&$nextIndicator.addClass("active")})}if($.support.transition&&this.$element.hasClass("slide")){this.$element.trigger(e);if(e.isDefaultPrevented())return;$next.addClass(type);$next[0].offsetWidth;$active.addClass(direction);$next.addClass(direction);$active.one($.support.transition.end,function(){$next.removeClass([type,direction].join(" ")).addClass("active");$active.removeClass(["active",direction].join(" "));that.sliding=false;setTimeout(function(){that.$element.trigger("slid")},0)}).emulateTransitionEnd(600)}else{this.$element.trigger(e);if(e.isDefaultPrevented())return;$active.removeClass("active");$next.addClass("active");this.sliding=false;this.$element.trigger("slid")}isCycling&&this.cycle();return this};var old=$.fn.carousel;$.fn.carousel=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.carousel");var options=$.extend({},Carousel.DEFAULTS,$this.data(),typeof option=="object"&&option);var action=typeof option=="string"?option:options.slide;if(!data)$this.data("bs.carousel",data=new Carousel(this,options));if(typeof option=="number")data.to(option);else if(action)data[action]();else if(options.interval)data.pause().cycle()})};$.fn.carousel.Constructor=Carousel;$.fn.carousel.noConflict=function(){$.fn.carousel=old;return this};$(document).on("click.bs.carousel.data-api","[data-slide], [data-slide-to]",function(e){var $this=$(this),href;var $target=$($this.attr("data-target")||(href=$this.attr("href"))&&href.replace(/.*(?=#[^\s]+$)/,""));var options=$.extend({},$target.data(),$this.data());var slideIndex=$this.attr("data-slide-to");if(slideIndex)options.interval=false;$target.carousel(options);if(slideIndex=$this.attr("data-slide-to")){$target.data("bs.carousel").to(slideIndex)}e.preventDefault()});$(window).on("load",function(){$('[data-ride="carousel"]').each(function(){var $carousel=$(this);$carousel.carousel($carousel.data())})})}(jQuery);+function($){"use strict";var Collapse=function(element,options){this.$element=$(element);this.options=$.extend({},Collapse.DEFAULTS,options);this.transitioning=null;if(this.options.parent)this.$parent=$(this.options.parent);if(this.options.toggle)this.toggle()};Collapse.DEFAULTS={toggle:true};Collapse.prototype.dimension=function(){var hasWidth=this.$element.hasClass("width");return hasWidth?"width":"height"};Collapse.prototype.show=function(){if(this.transitioning||this.$element.hasClass("in"))return;var startEvent=$.Event("show.bs.collapse");this.$element.trigger(startEvent);if(startEvent.isDefaultPrevented())return;var actives=this.$parent&&this.$parent.find("> .panel > .in");if(actives&&actives.length){var hasData=actives.data("bs.collapse");if(hasData&&hasData.transitioning)return;actives.collapse("hide");hasData||actives.data("bs.collapse",null)}var dimension=this.dimension();this.$element.removeClass("collapse").addClass("collapsing")[dimension](0);this.transitioning=1;var complete=function(){this.$element.removeClass("collapsing").addClass("in")[dimension]("auto");this.transitioning=0;this.$element.trigger("shown.bs.collapse")};if(!$.support.transition)return complete.call(this);var scrollSize=$.camelCase(["scroll",dimension].join("-"));this.$element.one($.support.transition.end,$.proxy(complete,this)).emulateTransitionEnd(350)[dimension](this.$element[0][scrollSize])};Collapse.prototype.hide=function(){if(this.transitioning||!this.$element.hasClass("in"))return;var startEvent=$.Event("hide.bs.collapse");this.$element.trigger(startEvent);if(startEvent.isDefaultPrevented())return;var dimension=this.dimension();this.$element[dimension](this.$element[dimension]())[0].offsetHeight;this.$element.addClass("collapsing").removeClass("collapse").removeClass("in");this.transitioning=1;var complete=function(){this.transitioning=0;this.$element.trigger("hidden.bs.collapse").removeClass("collapsing").addClass("collapse")};if(!$.support.transition)return complete.call(this);this.$element[dimension](0).one($.support.transition.end,$.proxy(complete,this)).emulateTransitionEnd(350)};Collapse.prototype.toggle=function(){this[this.$element.hasClass("in")?"hide":"show"]()};var old=$.fn.collapse;$.fn.collapse=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.collapse");var options=$.extend({},Collapse.DEFAULTS,$this.data(),typeof option=="object"&&option);if(!data)$this.data("bs.collapse",data=new Collapse(this,options));if(typeof option=="string")data[option]()})};$.fn.collapse.Constructor=Collapse;$.fn.collapse.noConflict=function(){$.fn.collapse=old;return this};$(document).on("click.bs.collapse.data-api","[data-toggle=collapse]",function(e){var $this=$(this),href;var target=$this.attr("data-target")||e.preventDefault()||(href=$this.attr("href"))&&href.replace(/.*(?=#[^\s]+$)/,"");var $target=$(target);var data=$target.data("bs.collapse");var option=data?"toggle":$this.data();var parent=$this.attr("data-parent");var $parent=parent&&$(parent);if(!data||!data.transitioning){if($parent)$parent.find('[data-toggle=collapse][data-parent="'+parent+'"]').not($this).addClass("collapsed");$this[$target.hasClass("in")?"addClass":"removeClass"]("collapsed")}$target.collapse(option)})}(jQuery);+function($){"use strict";var backdrop=".dropdown-backdrop";var toggle="[data-toggle=dropdown]";var Dropdown=function(element){var $el=$(element).on("click.bs.dropdown",this.toggle)};Dropdown.prototype.toggle=function(e){var $this=$(this);if($this.is(".disabled, :disabled"))return;var $parent=getParent($this);var isActive=$parent.hasClass("open");clearMenus();if(!isActive){if("ontouchstart"in document.documentElement&&!$parent.closest(".navbar-nav").length){$('<div class="dropdown-backdrop"/>').insertAfter($(this)).on("click",clearMenus)}$parent.trigger(e=$.Event("show.bs.dropdown"));if(e.isDefaultPrevented())return;$parent.toggleClass("open").trigger("shown.bs.dropdown");$this.focus()}return false};Dropdown.prototype.keydown=function(e){if(!/(38|40|27)/.test(e.keyCode))return;var $this=$(this);e.preventDefault();e.stopPropagation();if($this.is(".disabled, :disabled"))return;var $parent=getParent($this);var isActive=$parent.hasClass("open");if(!isActive||isActive&&e.keyCode==27){if(e.which==27)$parent.find(toggle).focus();return $this.click()}var $items=$("[role=menu] li:not(.divider):visible a",$parent);if(!$items.length)return;var index=$items.index($items.filter(":focus"));if(e.keyCode==38&&index>0)index--;if(e.keyCode==40&&index<$items.length-1)index++;if(!~index)index=0;$items.eq(index).focus()};function clearMenus(){$(backdrop).remove();$(toggle).each(function(e){var $parent=getParent($(this));if(!$parent.hasClass("open"))return;$parent.trigger(e=$.Event("hide.bs.dropdown"));if(e.isDefaultPrevented())return;$parent.removeClass("open").trigger("hidden.bs.dropdown")})}function getParent($this){var selector=$this.attr("data-target");if(!selector){selector=$this.attr("href");selector=selector&&/#/.test(selector)&&selector.replace(/.*(?=#[^\s]*$)/,"")}var $parent=selector&&$(selector);return $parent&&$parent.length?$parent:$this.parent()}var old=$.fn.dropdown;$.fn.dropdown=function(option){return this.each(function(){var $this=$(this);var data=$this.data("dropdown");if(!data)$this.data("dropdown",data=new Dropdown(this));if(typeof option=="string")data[option].call($this)})};$.fn.dropdown.Constructor=Dropdown;$.fn.dropdown.noConflict=function(){$.fn.dropdown=old;return this};$(document).on("click.bs.dropdown.data-api",clearMenus).on("click.bs.dropdown.data-api",".dropdown form",function(e){e.stopPropagation()}).on("click.bs.dropdown.data-api",toggle,Dropdown.prototype.toggle).on("keydown.bs.dropdown.data-api",toggle+", [role=menu]",Dropdown.prototype.keydown)}(jQuery);+function($){"use strict";var Modal=function(element,options){this.options=options;this.$element=$(element);this.$backdrop=this.isShown=null;if(this.options.remote){this.$element.load(this.options.remote)}};Modal.DEFAULTS={backdrop:true,keyboard:true,show:true};Modal.prototype.toggle=function(_relatedTarget){return this[!this.isShown?"show":"hide"](_relatedTarget)};Modal.prototype.show=function(_relatedTarget){var that=this;var e=$.Event("show.bs.modal",{relatedTarget:_relatedTarget});this.$element.trigger(e);if(this.isShown||e.isDefaultPrevented())return;this.isShown=true;this.escape();this.$element.on("click.dismiss.modal",'[data-dismiss="modal"]',$.proxy(this.hide,this));this.backdrop(function(){var transition=$.support.transition&&that.$element.hasClass("fade");if(!that.$element.parent().length){that.$element.appendTo(document.body)}that.$element.show();if(transition){that.$element[0].offsetWidth}that.$element.addClass("in").attr("aria-hidden",false);that.enforceFocus();var e=$.Event("shown.bs.modal",{relatedTarget:_relatedTarget});transition?that.$element.find(".modal-dialog").one($.support.transition.end,function(){that.$element.focus().trigger(e)}).emulateTransitionEnd(300):that.$element.focus().trigger(e)})};Modal.prototype.hide=function(e){if(e)e.preventDefault();e=$.Event("hide.bs.modal");this.$element.trigger(e);if(!this.isShown||e.isDefaultPrevented())return;this.isShown=false;this.escape();$(document).off("focusin.bs.modal");this.$element.removeClass("in").attr("aria-hidden",true).off("click.dismiss.modal");$.support.transition&&this.$element.hasClass("fade")?this.$element.one($.support.transition.end,$.proxy(this.hideModal,this)).emulateTransitionEnd(300):this.hideModal()};Modal.prototype.enforceFocus=function(){$(document).off("focusin.bs.modal").on("focusin.bs.modal",$.proxy(function(e){if(this.$element[0]!==e.target&&!this.$element.has(e.target).length){this.$element.focus()}},this))};Modal.prototype.escape=function(){if(this.isShown&&this.options.keyboard){this.$element.on("keyup.dismiss.bs.modal",$.proxy(function(e){e.which==27&&this.hide()},this))}else if(!this.isShown){this.$element.off("keyup.dismiss.bs.modal")}};Modal.prototype.hideModal=function(){var that=this;this.$element.hide();this.backdrop(function(){that.removeBackdrop();that.$element.trigger("hidden.bs.modal")})};Modal.prototype.removeBackdrop=function(){this.$backdrop&&this.$backdrop.remove();this.$backdrop=null};Modal.prototype.backdrop=function(callback){var that=this;var animate=this.$element.hasClass("fade")?"fade":"";if(this.isShown&&this.options.backdrop){var doAnimate=$.support.transition&&animate;this.$backdrop=$('<div class="modal-backdrop '+animate+'" />').appendTo(document.body);this.$element.on("click.dismiss.modal",$.proxy(function(e){if(e.target!==e.currentTarget)return;this.options.backdrop=="static"?this.$element[0].focus.call(this.$element[0]):this.hide.call(this)},this));if(doAnimate)this.$backdrop[0].offsetWidth;this.$backdrop.addClass("in");if(!callback)return;doAnimate?this.$backdrop.one($.support.transition.end,callback).emulateTransitionEnd(150):callback()}else if(!this.isShown&&this.$backdrop){this.$backdrop.removeClass("in");$.support.transition&&this.$element.hasClass("fade")?this.$backdrop.one($.support.transition.end,callback).emulateTransitionEnd(150):callback()}else if(callback){callback()}};var old=$.fn.modal;$.fn.modal=function(option,_relatedTarget){return this.each(function(){var $this=$(this);var data=$this.data("bs.modal");var options=$.extend({},Modal.DEFAULTS,$this.data(),typeof option=="object"&&option);if(options.remote){data=null}if(!data)$this.data("bs.modal",data=new Modal(this,options));if(typeof option=="string")data[option](_relatedTarget);else if(options.show)data.show(_relatedTarget);if(options.postShow){options.postShow();$this.find(".alert").hide()}})};$.fn.modal.Constructor=Modal;$.fn.modal.noConflict=function(){$.fn.modal=old;return this};$(document).on("click.bs.modal.data-api",'[data-toggle="modal"]',function(e){var $this=$(this);var href=$this.attr("href");var $target=$($this.attr("data-target")||href&&href.replace(/.*(?=#[^\s]+$)/,""));var option=$target.data("modal")?"toggle":$.extend({remote:!/#/.test(href)&&href},$target.data(),$this.data());e.preventDefault();$target.modal(option,this).one("hide",function(){$this.is(":visible")&&$this.focus()})});$(document).on("show.bs.modal",".modal",function(){$(document.body).addClass("modal-open")}).on("hidden.bs.modal",".modal",function(){$(document.body).removeClass("modal-open")})}(jQuery);+function($){"use strict";var Tooltip=function(element,options){this.type=this.options=this.enabled=this.timeout=this.hoverState=this.$element=null;this.init("tooltip",element,options)};Tooltip.DEFAULTS={animation:true,placement:"top",selector:false,template:'<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',trigger:"hover focus",title:"",delay:0,html:false,container:false};Tooltip.prototype.init=function(type,element,options){this.enabled=true;this.type=type;this.$element=$(element);this.options=this.getOptions(options);var triggers=this.options.trigger.split(" ");for(var i=triggers.length;i--;){var trigger=triggers[i];if(trigger=="click"){this.$element.on("click."+this.type,this.options.selector,$.proxy(this.toggle,this))}else if(trigger!="manual"){var eventIn=trigger=="hover"?"mouseenter":"focus";var eventOut=trigger=="hover"?"mouseleave":"blur";this.$element.on(eventIn+"."+this.type,this.options.selector,$.proxy(this.enter,this));this.$element.on(eventOut+"."+this.type,this.options.selector,$.proxy(this.leave,this))}}this.options.selector?this._options=$.extend({},this.options,{trigger:"manual",selector:""}):this.fixTitle()};Tooltip.prototype.getDefaults=function(){return Tooltip.DEFAULTS};Tooltip.prototype.getOptions=function(options){options=$.extend({},this.getDefaults(),this.$element.data(),options);if(options.delay&&typeof options.delay=="number"){options.delay={show:options.delay,hide:options.delay}}return options};Tooltip.prototype.getDelegateOptions=function(){var options={};var defaults=this.getDefaults();this._options&&$.each(this._options,function(key,value){if(defaults[key]!=value)options[key]=value});return options};Tooltip.prototype.enter=function(obj){var self=obj instanceof this.constructor?obj:$(obj.currentTarget)[this.type](this.getDelegateOptions()).data("bs."+this.type);clearTimeout(self.timeout);self.hoverState="in";if(!self.options.delay||!self.options.delay.show)return self.show();self.timeout=setTimeout(function(){if(self.hoverState=="in")self.show()},self.options.delay.show)};Tooltip.prototype.leave=function(obj){var self=obj instanceof this.constructor?obj:$(obj.currentTarget)[this.type](this.getDelegateOptions()).data("bs."+this.type);clearTimeout(self.timeout);self.hoverState="out";if(!self.options.delay||!self.options.delay.hide)return self.hide();self.timeout=setTimeout(function(){if(self.hoverState=="out")self.hide()},self.options.delay.hide)};Tooltip.prototype.show=function(){var e=$.Event("show.bs."+this.type);if(this.hasContent()&&this.enabled){this.$element.trigger(e);if(e.isDefaultPrevented())return;var $tip=this.tip();this.setContent();if(this.options.animation)$tip.addClass("fade");var placement=typeof this.options.placement=="function"?this.options.placement.call(this,$tip[0],this.$element[0]):this.options.placement;var autoToken=/\s?auto?\s?/i;var autoPlace=autoToken.test(placement);if(autoPlace)placement=placement.replace(autoToken,"")||"top";$tip.detach().css({top:0,left:0,display:"block"}).addClass(placement);this.options.container?$tip.appendTo(this.options.container):$tip.insertAfter(this.$element);var pos=this.getPosition();var actualWidth=$tip[0].offsetWidth;var actualHeight=$tip[0].offsetHeight;if(autoPlace){var $parent=this.$element.parent();var orgPlacement=placement;var docScroll=document.documentElement.scrollTop||document.body.scrollTop;var parentWidth=this.options.container=="body"?window.innerWidth:$parent.outerWidth();var parentHeight=this.options.container=="body"?window.innerHeight:$parent.outerHeight();var parentLeft=this.options.container=="body"?0:$parent.offset().left;placement=placement=="bottom"&&pos.top+pos.height+actualHeight-docScroll>parentHeight?"top":placement=="top"&&pos.top-docScroll-actualHeight<0?"bottom":placement=="right"&&pos.right+actualWidth>parentWidth?"left":placement=="left"&&pos.left-actualWidth<parentLeft?"right":placement;$tip.removeClass(orgPlacement).addClass(placement)}var calculatedOffset=this.getCalculatedOffset(placement,pos,actualWidth,actualHeight);this.applyPlacement(calculatedOffset,placement);this.$element.trigger("shown.bs."+this.type)}};Tooltip.prototype.applyPlacement=function(offset,placement){var replace;var $tip=this.tip();var width=$tip[0].offsetWidth;var height=$tip[0].offsetHeight;var marginTop=parseInt($tip.css("margin-top"),10);var marginLeft=parseInt($tip.css("margin-left"),10);if(isNaN(marginTop))marginTop=0;if(isNaN(marginLeft))marginLeft=0;offset.top=offset.top+marginTop;offset.left=offset.left+marginLeft;$tip.offset(offset).addClass("in");var actualWidth=$tip[0].offsetWidth;var actualHeight=$tip[0].offsetHeight;if(placement=="top"&&actualHeight!=height){replace=true;offset.top=offset.top+height-actualHeight}if(/bottom|top/.test(placement)){var delta=0;if(offset.left<0){delta=offset.left*-2;offset.left=0;$tip.offset(offset);actualWidth=$tip[0].offsetWidth;actualHeight=$tip[0].offsetHeight}this.replaceArrow(delta-width+actualWidth,actualWidth,"left")}else{this.replaceArrow(actualHeight-height,actualHeight,"top")}if(replace)$tip.offset(offset)};Tooltip.prototype.replaceArrow=function(delta,dimension,position){this.arrow().css(position,delta?50*(1-delta/dimension)+"%":"")};Tooltip.prototype.setContent=function(){var $tip=this.tip();var title=this.getTitle();$tip.find(".tooltip-inner")[this.options.html?"html":"text"](title);$tip.removeClass("fade in top bottom left right")};Tooltip.prototype.hide=function(){var that=this;var $tip=this.tip();var e=$.Event("hide.bs."+this.type);function complete(){if(that.hoverState!="in")$tip.detach()}this.$element.trigger(e);if(e.isDefaultPrevented())return;$tip.removeClass("in");$.support.transition&&this.$tip.hasClass("fade")?$tip.one($.support.transition.end,complete).emulateTransitionEnd(150):complete();this.$element.trigger("hidden.bs."+this.type);return this};Tooltip.prototype.fixTitle=function(){var $e=this.$element;if($e.attr("title")||typeof $e.attr("data-original-title")!="string"){$e.attr("data-original-title",$e.attr("title")||"").attr("title","")}};Tooltip.prototype.hasContent=function(){return this.getTitle()};Tooltip.prototype.getPosition=function(){var el=this.$element[0];return $.extend({},typeof el.getBoundingClientRect=="function"?el.getBoundingClientRect():{width:el.offsetWidth,height:el.offsetHeight},this.$element.offset())};Tooltip.prototype.getCalculatedOffset=function(placement,pos,actualWidth,actualHeight){return placement=="bottom"?{top:pos.top+pos.height,left:pos.left+pos.width/2-actualWidth/2}:placement=="top"?{top:pos.top-actualHeight,left:pos.left+pos.width/2-actualWidth/2}:placement=="left"?{top:pos.top+pos.height/2-actualHeight/2,left:pos.left-actualWidth}:{top:pos.top+pos.height/2-actualHeight/2,left:pos.left+pos.width}};Tooltip.prototype.getTitle=function(){var title;var $e=this.$element;var o=this.options;title=$e.attr("data-original-title")||(typeof o.title=="function"?o.title.call($e[0]):o.title);return title};Tooltip.prototype.tip=function(){return this.$tip=this.$tip||$(this.options.template)};Tooltip.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".tooltip-arrow")};Tooltip.prototype.validate=function(){if(!this.$element[0].parentNode){this.hide();this.$element=null;this.options=null}};Tooltip.prototype.enable=function(){this.enabled=true};Tooltip.prototype.disable=function(){this.enabled=false};Tooltip.prototype.toggleEnabled=function(){this.enabled=!this.enabled};Tooltip.prototype.toggle=function(e){var self=e?$(e.currentTarget)[this.type](this.getDelegateOptions()).data("bs."+this.type):this;self.tip().hasClass("in")?self.leave(self):self.enter(self)};Tooltip.prototype.destroy=function(){this.hide().$element.off("."+this.type).removeData("bs."+this.type)};var old=$.fn.tooltip;$.fn.tooltip=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.tooltip");var options=typeof option=="object"&&option;if(!data)$this.data("bs.tooltip",data=new Tooltip(this,options));if(typeof option=="string")data[option]()})};$.fn.tooltip.Constructor=Tooltip;$.fn.tooltip.noConflict=function(){$.fn.tooltip=old;return this}}(jQuery);+function($){"use strict";var Popover=function(element,options){this.init("popover",element,options)};if(!$.fn.tooltip)throw new Error("Popover requires tooltip.js");Popover.DEFAULTS=$.extend({},$.fn.tooltip.Constructor.DEFAULTS,{placement:"right",trigger:"click",content:"",template:'<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'});Popover.prototype=$.extend({},$.fn.tooltip.Constructor.prototype);Popover.prototype.constructor=Popover;Popover.prototype.getDefaults=function(){return Popover.DEFAULTS};Popover.prototype.setContent=function(){var $tip=this.tip();var title=this.getTitle();var content=this.getContent();$tip.find(".popover-title")[this.options.html?"html":"text"](title);$tip.find(".popover-content")[this.options.html?"html":"text"](content);$tip.removeClass("fade top bottom left right in");if(!$tip.find(".popover-title").html())$tip.find(".popover-title").hide()};Popover.prototype.hasContent=function(){return this.getTitle()||this.getContent()};Popover.prototype.getContent=function(){var $e=this.$element;var o=this.options;return $e.attr("data-content")||(typeof o.content=="function"?o.content.call($e[0]):o.content)};Popover.prototype.arrow=function(){return this.$arrow=this.$arrow||this.tip().find(".arrow")};Popover.prototype.tip=function(){if(!this.$tip)this.$tip=$(this.options.template);return this.$tip};var old=$.fn.popover;$.fn.popover=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.popover");var options=typeof option=="object"&&option;if(!data)$this.data("bs.popover",data=new Popover(this,options));if(typeof option=="string")data[option]()})};$.fn.popover.Constructor=Popover;$.fn.popover.noConflict=function(){$.fn.popover=old;return this}}(jQuery);+function($){"use strict";function ScrollSpy(element,options){var href;var process=$.proxy(this.process,this);this.$element=$(element).is("body")?$(window):$(element);this.$body=$("body");this.$scrollElement=this.$element.on("scroll.bs.scroll-spy.data-api",process);this.options=$.extend({},ScrollSpy.DEFAULTS,options);this.selector=(this.options.target||(href=$(element).attr("href"))&&href.replace(/.*(?=#[^\s]+$)/,"")||"")+" .nav li > a";this.offsets=$([]);this.targets=$([]);this.activeTarget=null;this.refresh();this.process()}ScrollSpy.DEFAULTS={offset:10};ScrollSpy.prototype.refresh=function(){var offsetMethod=this.$element[0]==window?"offset":"position";this.offsets=$([]);this.targets=$([]);var self=this;var $targets=this.$body.find(this.selector).map(function(){var $el=$(this);var href=$el.data("target")||$el.attr("href");var $href=/^#\w/.test(href)&&$(href);return $href&&$href.length&&[[$href[offsetMethod]().top+(!$.isWindow(self.$scrollElement.get(0))&&self.$scrollElement.scrollTop()),href]]||null}).sort(function(a,b){return a[0]-b[0]}).each(function(){self.offsets.push(this[0]);self.targets.push(this[1])})};ScrollSpy.prototype.process=function(){var scrollTop=this.$scrollElement.scrollTop()+this.options.offset;var scrollHeight=this.$scrollElement[0].scrollHeight||this.$body[0].scrollHeight;var maxScroll=scrollHeight-this.$scrollElement.height();var offsets=this.offsets;var targets=this.targets;var activeTarget=this.activeTarget;var i;if(scrollTop>=maxScroll){return activeTarget!=(i=targets.last()[0])&&this.activate(i)}for(i=offsets.length;i--;){activeTarget!=targets[i]&&scrollTop>=offsets[i]&&(!offsets[i+1]||scrollTop<=offsets[i+1])&&this.activate(targets[i])}};ScrollSpy.prototype.activate=function(target){this.activeTarget=target;$(this.selector).parents(".active").removeClass("active");var selector=this.selector+'[data-target="'+target+'"],'+this.selector+'[href="'+target+'"]';var active=$(selector).parents("li").addClass("active");if(active.parent(".dropdown-menu").length){active=active.closest("li.dropdown").addClass("active")}active.trigger("activate")};var old=$.fn.scrollspy;$.fn.scrollspy=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.scrollspy");var options=typeof option=="object"&&option;if(!data)$this.data("bs.scrollspy",data=new ScrollSpy(this,options));if(typeof option=="string")data[option]()})};$.fn.scrollspy.Constructor=ScrollSpy;$.fn.scrollspy.noConflict=function(){$.fn.scrollspy=old;return this};$(window).on("load",function(){$('[data-spy="scroll"]').each(function(){var $spy=$(this);$spy.scrollspy($spy.data())})})}(jQuery);+function($){"use strict";var Tab=function(element){this.element=$(element)};Tab.prototype.show=function(){var $this=this.element;var $ul=$this.closest("ul:not(.dropdown-menu)");var selector=$this.data("target");if(!selector){selector=$this.attr("href");selector=selector&&selector.replace(/.*(?=#[^\s]*$)/,"")}if($this.parent("li").hasClass("active"))return;var previous=$ul.find(".active:last a")[0];var e=$.Event("show.bs.tab",{relatedTarget:previous});$this.trigger(e);if(e.isDefaultPrevented())return;var $target=$(selector);this.activate($this.parent("li"),$ul);this.activate($target,$target.parent(),function(){$this.trigger({type:"shown.bs.tab",relatedTarget:previous})})};Tab.prototype.activate=function(element,container,callback){var $active=container.find("> .active");var transition=callback&&$.support.transition&&$active.hasClass("fade");function next(){$active.removeClass("active").find("> .dropdown-menu > .active").removeClass("active");element.addClass("active");if(transition){element[0].offsetWidth;element.addClass("in")}else{element.removeClass("fade")}if(element.parent(".dropdown-menu")){element.closest("li.dropdown").addClass("active")}callback&&callback()}transition?$active.one($.support.transition.end,next).emulateTransitionEnd(150):next();$active.removeClass("in")};var old=$.fn.tab;$.fn.tab=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.tab");if(!data)$this.data("bs.tab",data=new Tab(this));if(typeof option=="string")data[option]()
})};$.fn.tab.Constructor=Tab;$.fn.tab.noConflict=function(){$.fn.tab=old;return this};$(document).on("click.bs.tab.data-api",'[data-toggle="tab"], [data-toggle="pill"]',function(e){e.preventDefault();$(this).tab("show")})}(jQuery);+function($){"use strict";var Affix=function(element,options){this.options=$.extend({},Affix.DEFAULTS,options);this.$window=$(window).on("scroll.bs.affix.data-api",$.proxy(this.checkPosition,this)).on("click.bs.affix.data-api",$.proxy(this.checkPositionWithEventLoop,this));this.$element=$(element);this.affixed=this.unpin=null;this.checkPosition()};Affix.RESET="affix affix-top affix-bottom";Affix.DEFAULTS={offset:0};Affix.prototype.checkPositionWithEventLoop=function(){setTimeout($.proxy(this.checkPosition,this),1)};Affix.prototype.checkPosition=function(){if(!this.$element.is(":visible"))return;var scrollHeight=$(document).height();var scrollTop=this.$window.scrollTop();var position=this.$element.offset();var offset=this.options.offset;var offsetTop=offset.top;var offsetBottom=offset.bottom;if(typeof offset!="object")offsetBottom=offsetTop=offset;if(typeof offsetTop=="function")offsetTop=offset.top();if(typeof offsetBottom=="function")offsetBottom=offset.bottom();var affix=this.unpin!=null&&scrollTop+this.unpin<=position.top?false:offsetBottom!=null&&position.top+this.$element.height()>=scrollHeight-offsetBottom?"bottom":offsetTop!=null&&scrollTop<=offsetTop?"top":false;if(this.affixed===affix)return;if(this.unpin)this.$element.css("top","");this.affixed=affix;this.unpin=affix=="bottom"?position.top-scrollTop:null;this.$element.removeClass(Affix.RESET).addClass("affix"+(affix?"-"+affix:""));if(affix=="bottom"){this.$element.offset({top:document.body.offsetHeight-offsetBottom-this.$element.height()})}};var old=$.fn.affix;$.fn.affix=function(option){return this.each(function(){var $this=$(this);var data=$this.data("bs.affix");var options=typeof option=="object"&&option;if(!data)$this.data("bs.affix",data=new Affix(this,options));if(typeof option=="string")data[option]()})};$.fn.affix.Constructor=Affix;$.fn.affix.noConflict=function(){$.fn.affix=old;return this};$(window).on("load",function(){$('[data-spy="affix"]').each(function(){var $spy=$(this);var data=$spy.data();data.offset=data.offset||{};if(data.offsetBottom)data.offset.bottom=data.offsetBottom;if(data.offsetTop)data.offset.top=data.offsetTop;$spy.affix(data)})})}(jQuery);var LEA={};var Notebook={cache:{}};var Note={cache:{}};var Tag={};var Notebook={};var Share={};var Mobile={};var LeaAce={};var Converter;var MarkdownEditor;var ScrollLink;var MD;function trimLeft(str,substr){if(!substr||substr==" "){return $.trim(str)}while(str.indexOf(substr)==0){str=str.substring(substr.length)}return str}function json(str){return eval("("+str+")")}function t(){var args=arguments;if(args.length<=1){return args[0]}var text=args[0];if(!text){return text}var pattern="LEAAEL";text=text.replace(/\?/g,pattern);for(var i=1;i<=args.length;++i){text=text.replace(pattern,args[i])}return text}var tt=t;function arrayEqual(a,b){a=a||[];b=b||[];return a.join(",")==b.join(",")}function isArray(obj){return Object.prototype.toString.call(obj)==="[object Array]"}function isEmpty(obj){if(!obj){return true}if(isArray(obj)){if(obj.length==0){return true}}return false}function getFormJsonData(formId){var data=formArrDataToJson($("#"+formId).serializeArray());return data}function formArrDataToJson(arrData){var datas={};var arrObj={};for(var i in arrData){var attr=arrData[i].name;var value=arrData[i].value;if(attr.substring(attr.length-2,attr.length)=="[]"){attr=attr.substring(0,attr.length-2);if(arrObj[attr]==undefined){arrObj[attr]=[value]}else{arrObj[attr].push(value)}continue}datas[attr]=value}return $.extend(datas,arrObj)}function formSerializeDataToJson(formSerializeData){var arr=formSerializeData.split("&");var datas={};var arrObj={};for(var i=0;i<arr.length;++i){var each=arr[i].split("=");var attr=decodeURI(each[0]);var value=decodeURI(each[1]);if(attr.substring(attr.length-2,attr.length)=="[]"){attr=attr.substring(0,attr.length-2);if(arrObj[attr]==undefined){arrObj[attr]=[value]}else{arrObj[attr].push(value)}continue}datas[attr]=value}return $.extend(datas,arrObj)}function _ajaxCallback(ret,successFunc,failureFunc){if(ret===true||ret=="true"||typeof ret=="object"){if(ret&&typeof ret=="object"){if(ret.Msg=="NOTLOGIN"){alert("你还没有登录, 请先登录!");return}}if(typeof successFunc=="function"){successFunc(ret)}}else{if(typeof failureFunc=="function"){failureFunc(ret)}else{alert("error!")}}}function _ajax(type,url,param,successFunc,failureFunc,async){log("-------------------ajax:");log(url);log(param);if(typeof async=="undefined"){async=true}else{async=false}return $.ajax({type:type,url:url,data:param,async:async,success:function(ret){_ajaxCallback(ret,successFunc,failureFunc)},error:function(ret){_ajaxCallback(ret,successFunc,failureFunc)}})}function ajaxGet(url,param,successFunc,failureFunc,async){return _ajax("GET",url,param,successFunc,failureFunc,async)}function ajaxPost(url,param,successFunc,failureFunc,async){_ajax("POST",url,param,successFunc,failureFunc,async)}function ajaxPostJson(url,param,successFunc,failureFunc,async){log("-------------------ajaxPostJson:");log(url);log(param);if(typeof async=="undefined"){async=true}else{async=false}$.ajax({url:url,type:"POST",contentType:"application/json; charset=utf-8",datatype:"json",async:async,data:JSON.stringify(param),success:function(ret,stats){_ajaxCallback(ret,successFunc,failureFunc)},error:function(ret){_ajaxCallback(ret,successFunc,failureFunc)}})}function findParents(target,selector){if($(target).is(selector)){return $(target)}var parents=$(target).parents();for(var i=0;i<parents.length;++i){log(parents.eq(i));if(parents.eq(i).is(selector)){return parents.seq(i)}}return null}function getVendorPrefix(){var body=document.body||document.documentElement,style=body.style,vendor=["webkit","khtml","moz","ms","o"],i=0;while(i<vendor.length){if(typeof style[vendor[i]+"Transition"]==="string"){return vendor[i]}i++}}function editorIframeTabindex(index){var $i=$("#editorContent");$i.attr("tabindex",index);setTimeout(function(){$i.attr("tabindex",index)},500);setTimeout(function(){$i.attr("tabindex",index)},1e3)}LEA.isM=false;LEA.isMarkdownEditor=function(){return LEA.isM};function switchEditor(isMarkdown){LEA.isM=isMarkdown;if(!isMarkdown){$("#editor").show();$("#mdEditor").css("z-index",1).hide();editorIframeTabindex(2);$("#wmd-input").attr("tabindex",3);$("#leanoteNav").show()}else{$("#mdEditor").css("z-index",3).show();editorIframeTabindex(3);$("#wmd-input").attr("tabindex",2);$("#leanoteNav").hide()}}var previewToken="<div style='display: none'>FORTOKEN</div>";var clearIntervalForSetContent;function setEditorContent(content,isMarkdown,preview,callback){if(!content){content=""}if(clearIntervalForSetContent){clearInterval(clearIntervalForSetContent)}if(!isMarkdown){$("#editorContent").html(content);if(typeof tinymce!="undefined"&&tinymce.activeEditor){var editor=tinymce.activeEditor;editor.setContent(content);callback&&callback();editor.undoManager.clear()}else{clearIntervalForSetContent=setTimeout(function(){setEditorContent(content,false,false,callback)},100)}}else{if(MD){MD.setContent(content);callback&&callback()}else{clearIntervalForSetContent=setTimeout(function(){setEditorContent(content,true,false,callback)},100)}}}function previewIsEmpty(preview){if(!preview||preview.substr(0,previewToken.length)==previewToken){return true}return false}function isAceError(val){if(!val){return false}return val.indexOf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")!=-1}function getEditorContent(isMarkdown){if(!isMarkdown){var editor=tinymce.activeEditor;if(editor){var content=$(editor.getBody()).clone();content.find(".toggle-raw").remove();if(window.LeaAce&&LeaAce.getAce){var pres=content.find("pre");for(var i=0;i<pres.length;++i){var pre=pres.eq(i);var id=pre.attr("id");var aceEditor=LeaAce.getAce(id);if(aceEditor){var val=aceEditor.getValue();if(isAceError(val)){val=pre.html()}val=val.replace(/</g,"&lt").replace(/>/g,"&gt");pre.removeAttr("style","").removeAttr("contenteditable").removeClass("ace_editor");pre.html(val)}}}content.find("pinit").remove();content.find(".thunderpin").remove();content.find(".pin").parent().remove();content=$(content).html();if(content){while(true){var lastEndScriptPos=content.lastIndexOf("</script>");if(lastEndScriptPos==-1){return content}var length=content.length;if(length-9==lastEndScriptPos){var lastScriptPos=content.lastIndexOf("<script ");if(lastScriptPos==-1){lastScriptPos=content.lastIndexOf("<script>")}if(lastScriptPos!=-1){content=content.substring(0,lastScriptPos)}else{return content}}else{return content}}}return content}}else{return[MD.getContent(),"<div>"+$("#preview-contents").html()+"</div>"]}}LEA.editorStatus=true;function disableEditor(){var editor=tinymce.activeEditor;if(editor){editor.hide();LEA.editorStatus=false;$("#mceTollbarMark").show().css("z-index",1e3)}}function enableEditor(){if(LEA.editorStatus){return}$("#mceTollbarMark").css("z-index",-1).hide();var editor=tinymce.activeEditor;if(editor){editor.show()}}function showDialog(id,options){$("#leanoteDialog #modalTitle").html(options.title);$("#leanoteDialog .modal-body").html($("#"+id+" .modal-body").html());$("#leanoteDialog .modal-footer").html($("#"+id+" .modal-footer").html());delete options.title;options.show=true;$("#leanoteDialog").modal(options)}function hideDialog(timeout){if(!timeout){timeout=0}setTimeout(function(){$("#leanoteDialog").modal("hide")},timeout)}function closeDialog(){$(".modal").modal("hide")}function showDialog2(id,options){options=options||{};options.show=true;$(id).modal(options)}function hideDialog2(id,timeout){if(!timeout){timeout=0}setTimeout(function(){$(id).modal("hide")},timeout)}function showDialogRemote(url,data){data=data||{};url+="?";for(var i in data){url+=i+"="+data[i]+"&"}$("#leanoteDialogRemote").modal({remote:url})}function hideDialogRemote(timeout){if(timeout){setTimeout(function(){$("#leanoteDialogRemote").modal("hide")},timeout)}else{$("#leanoteDialogRemote").modal("hide")}}$(function(){if($.pnotify){$.pnotify.defaults.delay=1e3}});function notifyInfo(text){$.pnotify({title:"通知",text:text,type:"info",styling:"bootstrap"})}function notifyError(text){$.pnotify.defaults.delay=2e3;$.pnotify({title:"通知",text:text,type:"error",styling:"bootstrap"})}function notifySuccess(text){$.pnotify({title:"通知",text:text,type:"success",styling:"bootstrap"})}Date.prototype.format=function(fmt){var o={"M+":this.getMonth()+1,"d+":this.getDate(),"h+":this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"q+":Math.floor((this.getMonth()+3)/3),S:this.getMilliseconds()};if(/(y+)/.test(fmt))fmt=fmt.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length));for(var k in o)if(new RegExp("("+k+")").test(fmt))fmt=fmt.replace(RegExp.$1,RegExp.$1.length==1?o[k]:("00"+o[k]).substr((""+o[k]).length));return fmt};function goNowToDatetime(goNow){if(!goNow){return""}return goNow.substr(0,10)+" "+goNow.substr(11,8)}function getCurDate(){return(new Date).format("yyyy-M-d")}function enter(parent,children,func){if(!parent){parent="body"}$(parent).on("keydown",children,function(e){if(e.keyCode==13){func.call(this)}})}function enterBlur(parent,children){if(!parent){parent="body"}if(!children){children=parent;parent="body"}$(parent).on("keydown",children,function(e){if(e.keyCode==13){$(this).trigger("blur")}})}function getObjectId(){return ObjectId()}function resizeEditor(second){return;var ifrParent=$("#editorContent_ifr").parent();ifrParent.css("overflow","auto");var height=$("#editorContent").height();ifrParent.height(height);$("#editorContent_ifr").height(height)}function showMsg(msg,timeout){$("#msg").html(msg);if(timeout){setTimeout(function(){$("#msg").html("")},timeout)}}function showMsg2(id,msg,timeout){$(id).html(msg);if(timeout){setTimeout(function(){$(id).html("")},timeout)}}function showAlert(id,msg,type,id2Focus){$(id).html(msg).removeClass("alert-danger").removeClass("alert-success").removeClass("alert-warning").addClass("alert-"+type).show();if(id2Focus){$(id2Focus).focus()}}function hideAlert(id,timeout){if(timeout){setTimeout(function(){$(id).hide()},timeout)}else{$(id).hide()}}function post(url,param,func,btnId){var btnPreText;if(btnId){$(btnId).button("loading")}ajaxPost(url,param,function(ret){if(btnId){$(btnId).button("reset")}if(typeof ret=="object"){if(typeof func=="function"){func(ret)}}else{alert("leanote出现了错误!")}})}function isEmail(email){var myreg=/^([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9\-]+@([a-zA-Z0-9\-]+[_|\_|\.|\-]?)*[a-zA-Z0-9\-]+\.[0-9a-zA-Z]{2,3}$/;return myreg.test(email)}function isEmailFromInput(inputId,msgId,selfBlankMsg,selfInvalidMsg){var val=$(inputId).val();var msg=function(){};if(msgId){msg=function(msgId,msg){showAlert(msgId,msg,"danger",inputId)}}if(!val){msg(msgId,selfBlankMsg||getMsg("inputEmail"))}else if(!isEmail(val)){msg(msgId,selfInvalidMsg||getMsg("errorEmail"))}else{return val}}function initCopy(aId,postFunc){var clip=new ZeroClipboard(document.getElementById(aId),{moviePath:"/js/ZeroClipboard/ZeroClipboard.swf"});clip.on("complete",function(client,args){postFunc(args)})}function showLoading(){$("#loading").css("visibility","visible")}function hideLoading(){$("#loading").css("visibility","hidden")}function setCookie(c_name,value,expiredays){var exdate=new Date;exdate.setDate(exdate.getDate()+expiredays);document.cookie=c_name+"="+escape(value)+(expiredays==null?"":";expires="+exdate.toGMTString())}function logout(){setCookie("LEANOTE_SESSION","",-1);location.href=UrlPrefix+"/logout?id=1"}function getImageSize(url,callback){var img=document.createElement("img");function done(width,height){img.parentNode.removeChild(img);callback({width:width,height:height})}img.onload=function(){done(img.clientWidth,img.clientHeight)};img.onerror=function(){done()};img.src=url;var style=img.style;style.visibility="hidden";style.position="fixed";style.bottom=style.left=0;style.width=style.height="auto";document.body.appendChild(img)}function hiddenIframeBorder(){$(".mce-window iframe").attr("frameborder","no").attr("scrolling","no")}var email2LoginAddress={"qq.com":"http://mail.qq.com","gmail.com":"http://mail.google.com","sina.com":"http://mail.sina.com.cn","163.com":"http://mail.163.com","126.com":"http://mail.126.com","yeah.net":"http://www.yeah.net/","sohu.com":"http://mail.sohu.com/","tom.com":"http://mail.tom.com/","sogou.com":"http://mail.sogou.com/","139.com":"http://mail.10086.cn/","hotmail.com":"http://www.hotmail.com","live.com":"http://login.live.com/","live.cn":"http://login.live.cn/","live.com.cn":"http://login.live.com.cn","189.com":"http://webmail16.189.cn/webmail/","yahoo.com.cn":"http://mail.cn.yahoo.com/","yahoo.cn":"http://mail.cn.yahoo.com/","eyou.com":"http://www.eyou.com/","21cn.com":"http://mail.21cn.com/","188.com":"http://www.188.com/","foxmail.coom":"http://www.foxmail.com"};function getEmailLoginAddress(email){if(!email){return}var arr=email.split("@");if(!arr||arr.length<2){return}var addr=arr[1];return email2LoginAddress[addr]||"http://mail."+addr}function reIsOk(re){return re&&typeof re=="object"&&re.Ok}LEA.bookmark=null;LEA.hasBookmark=false;function saveBookmark(){try{LEA.bookmark=tinymce.activeEditor.selection.getBookmark();if(LEA.bookmark&&LEA.bookmark.id){var $ic=$($("#editorContent_ifr").contents());var $body=$ic.find("body");var $p=$body.children().eq(0);if($p.is("span")){var $children=$p;var $c=$children.eq(0);if($c.attr("id")==LEA.bookmark.id+"_start"){LEA.hasBookmark=false;$c.remove()}else{LEA.hasBookmark=true}}else if($p.is("p")){var $children=$p.children();if($children.length==1&&$.trim($p.text())==""){var $c=$children.eq(0);if($c.attr("id")==LEA.bookmark.id+"_start"){LEA.hasBookmark=false;$p.remove()}else{LEA.hasBookmark=true}}else{LEA.hasBookmark=true}}}}catch(e){}}function restoreBookmark(){try{if(LEA.hasBookmark){var editor=tinymce.activeEditor;editor.focus();editor.selection.moveToBookmark(LEA.bookmark)}}catch(e){}}var vd={isInt:function(o){var intPattern=/^0$|^[1-9]\d*$/;result=intPattern.test(o);return result},isNumeric:function(o){return $.isNumeric(o)},isFloat:function(floatValue){var floatPattern=/^0(\.\d+)?$|^[1-9]\d*(\.\d+)?$/;result=floatPattern.test(floatValue);return result},isEmail:function(emailValue){var emailPattern=/^([a-zA-Z0-9]+[_|\_|\.|\-]?)*[a-zA-Z0-9\-]+@([a-zA-Z0-9\-]+[_|\_|\.|\-]?)*[a-zA-Z0-9\-]+\.[0-9a-zA-Z]{2,3}$/;result=emailPattern.test(emailValue);return result},isBlank:function(o){return!$.trim(o)},has_special_chars:function(o){return/['"#$%&\^<>\?*]/.test(o)},init:function(form,rule_funcs){var get_val=function(target){if(target.is(":checkbox")){var name=target.attr("name");var val=$('input[name="'+name+'"]:checked').length;return val}else if(target.is(":radio")){}else{return target.val()}};var default_rule_funcs={required:function(target){return get_val(target)},min:function(target,rule){var val=get_val(target);if(val===""&&!is_required(target)){return true}if(val<rule.data){return false}return true},minLength:function(target,rule){var val=get_val(target);if(val===""&&!is_required(target)){return true}if(val.length<rule.data){return false}return true},email:function(target,rule){var val=get_val(target);if(val===""&&!is_required(target)){return true}return vd.isEmail(val)},noSpecialChars:function(target){var val=get_val(target);if(!val){return true}if(/[^0-9a-zzA-Z_\-]/.test(val)){return false}return true},password:function(target,rule){var val=get_val(target);if(val===""&&!is_required(target)){return true}return val.length>=6},equalTo:function(target,rule){var val=get_val(target);if(val===""&&!is_required(target)){return true}return $(rule.data).val()==val}};rule_funcs=rule_funcs||{};rule_funcs=$.extend(default_rule_funcs,rule_funcs);var rules={};var msg_targets={};function is_required(target){var name=get_name(target);var rules=get_rules(target,name);var required_rule=rules[0];if(required_rule["rule"]=="required"){return true}return false}function get_rules(target,name){if(!rules[name]){rules[name]=eval("("+target.data("rules")+")")}return rules[name]}function get_msg_target(target,name){if(!msg_targets[name]){var t=target.data("msg_target");if(!t){var msg_o=$('<div class="help-block alert alert-warning" style="display: block;"></div>');target.parent().append(msg_o);msg_targets[name]=msg_o}else{msg_targets[name]=$(t)}}return msg_targets[name]}function hide_msg(target,name){var msgT=get_msg_target(target,name);if(!msgT.hasClass("alert-success")){msgT.hide()}}function show_msg(target,name,msg,msgData){var t=get_msg_target(target,name);t.html(getMsg(msg,msgData)).removeClass("hide alert-success").addClass("alert-danger").show()}function pre_fix(target){var fix_name=target.data("pre_fix");if(!fix_name){return}switch(fix_name){case"int":int_fix(target);break;case"price":price_fix(target);break;case"decimal":decimal_fix(target);break}}function apply_rules(target,name){var rules=get_rules(target,name);pre_fix(target);if(!rules){return true}for(var i=0;i<rules.length;++i){var rule=rules[i];var rule_func_name=rule.rule;var msg=rule.msg;var msgData=rule.msgData;if(!rule_funcs[rule_func_name](target,rule)){show_msg(target,name,msg,msgData);return false}}hide_msg(target,name);var post_rule=target.data("post_rule");if(post_rule){setTimeout(function(){var post_target=$(post_rule);apply_rules(post_target,get_name(post_target))},0)}return true}function focus_func(e){var target=$(e.target);var name=get_name(target);hide_msg(target,name);pre_fix(target)}function unfocus_func(e){var target=$(e.target);var name=get_name(target);apply_rules(target,name)}function get_name(target){return target.data("u_name")||target.attr("name")||target.attr("id")}var $allElems=$(form).find("[data-rules]");var $form=$(form);$form.on({keyup:function(e){if(e.keyCode!=13){focus_func(e)}},blur:unfocus_func},'input[type="text"], input[type="password"]');$form.on({change:function(e){if($(this).val()){focus_func(e)}else{unfocus_func(e)}}},"select");$form.on({change:function(e){unfocus_func(e)}},'input[type="checkbox"]');this.valid=function(){var $ts=$allElems;var is_valid=true;for(var i=0;i<$ts.length;++i){var target=$ts.eq(i);var name=get_name(target);if(!apply_rules(target,name)){is_valid=false;target.focus();return false}else{}}return is_valid};this.validElement=function(targets){var targets=$(targets);var ok=true;for(var i=0;i<targets.length;++i){var target=targets.eq(i);var name=get_name(target);if(!apply_rules(target,name)){ok=false}}return ok}}};function getHashObject(){var hash=location.hash;if(!hash){return{}}var hashKV=hash.substr(1);var kvs=hashKV.split("&");var kvsObj={};for(var i=0;i<kvs.length;++i){var kv=kvs[i].split("=");if(kv.length==2){kvsObj[kv[0]]=kv[1]}}return kvsObj}function getHash(key,value){var kvs=getHashObject();return kvs[key]}function setHash(key,value){var hash=location.hash;if(!hash){location.href="#"+key+"="+value;return}var kvs=getHashObject();kvs[key]=value;var str="";for(var i in kvs){if(kvs[i]){if(str){str+="&"}str+=i+"="+kvs[i]}}location.href="#"+str}var trimTitle=function(title){return title.replace(/<.*?script.*?>/g,"")};Note.curNoteId="";Note.interval="";Note.itemIsBlog='<div class="item-blog"><i class="fa fa-bold" title="blog"></i></div><div class="item-setting"><i class="fa fa-cog" title="setting"></i></div>';Note.itemTplNoImg='<li href="#" class="item ?" noteId="?">';Note.itemTplNoImg+=Note.itemIsBlog+'<div class="item-desc"><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';Note.itemTpl='<li href="#" class="item ? item-image" noteId="?"><div class="item-thumb" style=""><img src="?"/></div>';Note.itemTpl+=Note.itemIsBlog+'<div class="item-desc" style=""><p class="item-title">?</p><p class="item-info"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span></p><p class="desc">?</p></div></li>';Note.newItemTpl='<li href="#" class="item item-active ?" fromUserId="?" noteId="?">';Note.newItemTpl+=Note.itemIsBlog+'<div class="item-desc" style="right: 0px;"><p class="item-title">?</p><p class="item-text"><i class="fa fa-book"></i> <span class="note-notebook">?</span> <i class="fa fa-clock-o"></i> <span class="updated-time">?</span><br /><span class="desc">?</span></p></div></li>';Note.noteItemListO=$("#noteItemList");Note.cacheByNotebookId={all:{}};Note.notebookIds={};Note.isReadOnly=false;Note.intervalTime=6e5;Note.startInterval=function(){Note.interval=setInterval(function(){log("自动保存开始...");changedNote=Note.curChangedSaveIt(false)},Note.intervalTime)};Note.stopInterval=function(){clearInterval(Note.interval);setTimeout(function(){Note.startInterval()},Note.intervalTime)};Note.addNoteCache=function(note){Note.cache[note.NoteId]=note;Note.clearCacheByNotebookId(note.NotebookId)};Note.setNoteCache=function(content,clear){if(!Note.cache[content.NoteId]){Note.cache[content.NoteId]=content}else{$.extend(Note.cache[content.NoteId],content)}if(clear==undefined){clear=true}if(clear){Note.clearCacheByNotebookId(content.NotebookId)}};Note.getCurNote=function(){var self=this;if(self.curNoteId==""){return null}return self.cache[self.curNoteId]};Note.getNote=function(noteId){var self=this;return self.cache[noteId]};Note.clearCacheByNotebookId=function(notebookId){if(notebookId){Note.cacheByNotebookId[notebookId]={};Note.cacheByNotebookId["all"]={};Note.notebookIds[notebookId]=true}};Note.notebookHasNotes=function(notebookId){var notes=Note.getNotesByNotebookId(notebookId);return!isEmpty(notes)};Note.getNotesByNotebookId=function(notebookId,sortBy,isAsc){if(!sortBy){sortBy="UpdatedTime"}if(isAsc=="undefined"){isAsc=false}if(!notebookId){notebookId="all"}if(!Note.cacheByNotebookId[notebookId]){return[]}if(Note.cacheByNotebookId[notebookId][sortBy]){return Note.cacheByNotebookId[notebookId][sortBy]}else{}var notes=[];var sortBys=[];for(var i in Note.cache){if(!i){continue}var note=Note.cache[i];if(note.IsTrash||note.IsShared){continue}if(notebookId=="all"||note.NotebookId==notebookId){notes.push(note)}}notes.sort(function(a,b){var t1=a[sortBy];var t2=b[sortBy];if(isAsc){if(t1<t2){return-1}else if(t1>t2){return 1}}else{if(t1<t2){return 1}else if(t1>t2){return-1}}return 0});Note.cacheByNotebookId[notebookId][sortBy]=notes;return notes};Note.curNoteIsDirtied=function(){var me=this;var note=me.getCurNote();if(note){note.isDirty=true}};Note.renderNotesAndFirstOneContent=function(ret){if(!isArray(ret)){return}Note.renderNotes(ret);if(!isEmpty(ret[0])){Note.changeNoteForPjax(ret[0].NoteId,true,false)}else{}};Note.curHasChanged=function(force){if(force==undefined){force=true}var cacheNote=Note.cache[Note.curNoteId]||{};var title=$("#noteTitle").val();var tags=Tag.getTags();var contents=getEditorContent(cacheNote.IsMarkdown);var content,preview;var contentText;if(isArray(contents)){content=contents[0];preview=contents[1];contentText=content;if(content&&previewIsEmpty(preview)&&Converter){preview=Converter.makeHtml(content)}if(!content){preview=""}cacheNote.Preview=preview}else{content=contents;try{contentText=$(content).text()}catch(e){}}var hasChanged={hasChanged:false,IsNew:cacheNote.IsNew,IsMarkdown:cacheNote.IsMarkdown,FromUserId:cacheNote.FromUserId,NoteId:cacheNote.NoteId,NotebookId:cacheNote.NotebookId,Version:cacheNote.Version||0};if(hasChanged.IsNew){$.extend(hasChanged,cacheNote)}else{if(!cacheNote.isDirty){log("no dirty");hasChanged.hasChanged=false;return hasChanged}}if(cacheNote.Title!=title){hasChanged.hasChanged=true;hasChanged.Title=title;if(!hasChanged.Title){}}if(!arrayEqual(cacheNote.Tags,tags)){hasChanged.hasChanged=true;hasChanged.Tags=tags.join(",")}if(force&&cacheNote.Content!=content||!force&&(!cacheNote.IsMarkdown&&$(cacheNote.Content).text()!=contentText||cacheNote.IsMarkdown&&cacheNote.Content!=contentText)){hasChanged.hasChanged=true;hasChanged.Content=content;var c=preview||content;if(!cacheNote.HasSelfDefined||!cacheNote.IsBlog){hasChanged.Desc=Note.genDesc(c);hasChanged.ImgSrc=Note.getImgSrc(c);hasChanged.Abstract=Note.genAbstract(c)}}else{log("text相同");log(cacheNote.Content==content)}hasChanged["UserId"]=cacheNote["UserId"]||"";return hasChanged};Note.genDesc=function(content){if(!content){return""}content=content.replace(/<br \/>/g," <br />");content=content.replace(/<\/p>/g," </p>");content=content.replace(/<\/div>/g," </div>");content=$("<div></div>").html(content).text();content=content.replace(/</g,"&lt;");content=content.replace(/>/g,"&gt;");if(content.length<300){return content}return content.substring(0,300)};Note.genAbstract=function(content,len){if(!content){return""}if(len==undefined){len=1e3}if(content.length<len){return content}var isCode=false;var isHTML=false;var n=0;var result="";var maxLen=len;for(var i=0;i<content.length;++i){var temp=content[i];if(temp=="<"){isCode=true}else if(temp=="&"){isHTML=true}else if(temp==">"&&isCode){n=n-1;isCode=false}else if(temp==";"&&isHTML){isHTML=false}if(!isCode&&!isHTML){n=n+1}result+=temp;if(n>=maxLen){break}}var d=document.createElement("div");d.innerHTML=result;return d.innerHTML};Note.getImgSrc=function(content){if(!content){return""}var imgs=$(content).find("img");for(var i in imgs){var src=imgs.eq(i).attr("src");if(src){return src}}return""};Note.saveInProcess={};Note.savePool={};Note.curChangedSaveIt=function(force,callback){var me=this;if(!Note.curNoteId||Note.isReadOnly){return}var hasChanged=Note.curHasChanged(force);if(hasChanged.hasChanged||hasChanged.IsNew){Note.renderChangedNote(hasChanged);delete hasChanged.hasChanged;showMsg(getMsg("saving"));me.saveInProcess[hasChanged.NoteId]=true;ajaxPost("/note/updateNoteOrContent",hasChanged,function(ret){me.saveInProcess[hasChanged.NoteId]=false;if(hasChanged.IsNew){ret.IsNew=false;Note.setNoteCache(ret,false);Pjax.changeNote(ret)}callback&&callback();showMsg(getMsg("saveSuccess"),1e3)});if(hasChanged["Tags"]!=undefined&&typeof hasChanged["Tags"]=="string"){hasChanged["Tags"]=hasChanged["Tags"].split(",")}Note.setNoteCache(hasChanged,false);Note.setNoteCache({NoteId:hasChanged.NoteId,UpdatedTime:(new Date).format("yyyy-MM-ddThh:mm:ss.S")},false);return hasChanged}return false};Note.updatePoolNote=function(){var me=this;for(var noteId in me.savePool){if(!noteId){continue}delete me.savePool[noteId];var hasChanged=me.savePool[noteId];me.saveInProcess[noteId]=true;ajaxPost("/note/updateNoteOrContent",hasChanged,function(ret){me.saveInProcess[noteId]=false})}};Note.updatePoolNoteInterval=null;Note.startUpdatePoolNoteInterval=function(){return;var me=this;if(me.updatePoolNoteInterval){return}me.updatePoolNoteInterval=setTimeout(function(){log("update pool");me.updatePoolNote()},1e3)};Note.selectTarget=function(target){$(".item").removeClass("item-active");$(target).addClass("item-active")};Note.showContentLoading=function(){$("#noteMaskForLoading").css("z-index",99999)};Note.hideContentLoading=function(){$("#noteMaskForLoading").css("z-index",-1)};Note.directToNote=function(noteId){var $p=$("#noteItemList");var pHeight=$p.height();var pTop=$("[noteId='"+noteId+"']").position().top;var scrollTop=$p.scrollTop();pTop+=scrollTop;if(pTop>=scrollTop&&pTop<=pHeight+scrollTop){}else{var top=pTop;log("定位到特定note, 在可视范围内");if(!LEA.isMobile&&!Mobile.isMobile()){$("#noteItemList").scrollTop(top);$("#noteItemList").slimScroll({scrollTo:top+"px",height:"100%",onlyScrollBar:true})}else{}}};Note.changeNoteForPjax=function(noteId,mustPush,needTargetNotebook){var me=this;var note=me.getNote(noteId);if(!note){return}var isShare=note.Perm!=undefined;if(needTargetNotebook==undefined){needTargetNotebook=true}me.changeNote(noteId,isShare,true,function(note){if(mustPush==undefined){mustPush=true}if(mustPush){Pjax.changeNote(note)}if(needTargetNotebook){Note.directToNote(noteId)}});if(needTargetNotebook){if(isShare){if($("#myShareNotebooks").hasClass("closed")){$("#myShareNotebooks .folderHeader").trigger("click")}}else{if($("#myNotebooks").hasClass("closed")){$("#myNotebooks .folderHeader").trigger("click")}}Notebook.expandNotebookTo(note.NotebookId)}};Note.contentAjax=null;Note.contentAjaxSeq=1;Note.changeNote=function(selectNoteId,isShare,needSaveChanged,callback){var self=this;Note.stopInterval();var target=$(tt('[noteId="?"]',selectNoteId));Note.selectTarget(target);if(needSaveChanged==undefined){needSaveChanged=true}if(needSaveChanged){var changedNote=Note.curChangedSaveIt()}Note.curNoteId="";var cacheNote=Note.cache[selectNoteId];if(!isShare){if(cacheNote.Perm!=undefined){isShare=true}}var hasPerm=!isShare||Share.hasUpdatePerm(selectNoteId);if(hasPerm){Note.hideReadOnly();Note.renderNote(cacheNote)}else{Note.renderNoteReadOnly(cacheNote)}switchEditor(cacheNote.IsMarkdown);Attach.renderNoteAttachNum(selectNoteId,true);Note.contentAjaxSeq++;var seq=Note.contentAjaxSeq;function setContent(ret){Note.contentAjax=null;if(seq!=Note.contentAjaxSeq){return}Note.setNoteCache(ret,false);ret=Note.cache[selectNoteId];Note.renderNoteContent(ret);self.hideContentLoading();callback&&callback(ret)}if(cacheNote.Content){setContent(cacheNote);return}var url="/note/getNoteContent";var param={noteId:selectNoteId};if(isShare){url="/share/getShareNoteContent";param.sharedUserId=cacheNote.UserId}self.showContentLoading();if(Note.contentAjax!=null){Note.contentAjax.abort()}Note.contentAjax=ajaxGet(url,param,setContent)};Note.renderChangedNote=function(changedNote){if(!changedNote){return}var $leftNoteNav=$(tt('[noteId="?"]',changedNote.NoteId));if(changedNote.Title){$leftNoteNav.find(".item-title").html(changedNote.Title)}if(changedNote.Desc){$leftNoteNav.find(".desc").html(changedNote.Desc)}if(changedNote.ImgSrc){$thumb=$leftNoteNav.find(".item-thumb");if($thumb.length>0){$thumb.find("img").attr("src",changedNote.ImgSrc)}else{$leftNoteNav.append(tt('<div class="item-thumb" style=""><img src="?"></div>',changedNote.ImgSrc));$leftNoteNav.addClass("item-image")}$leftNoteNav.find(".item-desc").removeAttr("style")}else if(changedNote.ImgSrc==""){$leftNoteNav.find(".item-thumb").remove();$leftNoteNav.removeClass("item-image")}};Note.clearNoteInfo=function(){Note.curNoteId="";Tag.clearTags();$("#noteTitle").val("");setEditorContent("");$("#noteRead").hide()};Note.clearNoteList=function(){Note.noteItemListO.html("")};Note.clearAll=function(){Note.curNoteId="";Note.clearNoteInfo();Note.clearNoteList()};Note.renderNote=function(note){if(!note){return}$("#noteTitle").val(trimTitle(note.Title));Tag.renderTags(note.Tags);note.isDirty=false};Note.renderNoteContent=function(content){setEditorContent(content.Content,content.IsMarkdown,content.Preview,function(){Note.curNoteId=content.NoteId;Note.toggleReadOnly()});Note.curNoteId=content.NoteId};Note.showEditorMask=function(){$("#editorMask").css("z-index",10).show();if(Notebook.curNotebookIsTrashOrAll()){$("#editorMaskBtns").hide();$("#editorMaskBtnsEmpty").show()}else{$("#editorMaskBtns").show();$("#editorMaskBtnsEmpty").hide()}};Note.hideEditorMask=function(){$("#editorMask").css("z-index",-10).hide()};Note.renderNotesC=0;Note.renderNotes=function(notes,forNewNote,isShared){var renderNotesC=++Note.renderNotesC;if(!LEA.isMobile&&!Mobile.isMobile()){$("#noteItemList").slimScroll({scrollTo:"0px",height:"100%",onlyScrollBar:true})}if(!notes||typeof notes!="object"||notes.length<=0){if(!forNewNote){Note.showEditorMask()}return}Note.hideEditorMask();if(forNewNote==undefined){forNewNote=false}if(!forNewNote){Note.noteItemListO.html("")}var len=notes.length;var c=Math.ceil(len/20);Note._renderNotes(notes,forNewNote,isShared,1);for(var i=0;i<len;++i){var note=notes[i];Note.setNoteCache(note,false);if(isShared){Share.setCache(note)}}for(var i=1;i<c;++i){setTimeout(function(i){return function(){if(renderNotesC==Note.renderNotesC){Note._renderNotes(notes,forNewNote,isShared,i+1)}}}(i),i*2e3)}};Note._renderNotes=function(notes,forNewNote,isShared,tang){var baseClasses="item-my";if(isShared){baseClasses="item-shared"}var len=notes.length;for(var i=(tang-1)*20;i<len&&i<tang*20;++i){var classes=baseClasses;if(!forNewNote&&i==0){classes+=" item-active"}var note=notes[i];var tmp;note.Title=trimTitle(note.Title);if(note.ImgSrc){tmp=tt(Note.itemTpl,classes,note.NoteId,note.ImgSrc,note.Title,Notebook.getNotebookTitle(note.NotebookId),goNowToDatetime(note.UpdatedTime),note.Desc)}else{tmp=tt(Note.itemTplNoImg,classes,note.NoteId,note.Title,Notebook.getNotebookTitle(note.NotebookId),goNowToDatetime(note.UpdatedTime),note.Desc)}if(!note.IsBlog){tmp=$(tmp);tmp.find(".item-blog").hide()}Note.noteItemListO.append(tmp)}};Note.newNote=function(notebookId,isShare,fromUserId,isMarkdown){switchEditor(isMarkdown);Note.hideEditorMask();Note.hideReadOnly();Note.stopInterval();Note.curChangedSaveIt();var note={NoteId:getObjectId(),Title:"",Tags:[],Content:"",NotebookId:notebookId,IsNew:true,FromUserId:fromUserId,IsMarkdown:isMarkdown};Note.addNoteCache(note);Attach.clearNoteAttachNum();var newItem="";var baseClasses="item-my";if(isShare){baseClasses="item-shared"}var notebook=Notebook.getNotebook(notebookId);var notebookTitle=notebook?notebook.Title:"";var curDate=getCurDate();if(isShare){newItem=tt(Note.newItemTpl,baseClasses,fromUserId,note.NoteId,note.Title,notebookTitle,curDate,"")}else{newItem=tt(Note.newItemTpl,baseClasses,"",note.NoteId,note.Title,notebookTitle,curDate,"")}if(!notebook.IsBlog){newItem=$(newItem);newItem.find(".item-blog").hide()}if(!Notebook.isCurNotebook(notebookId)){Note.clearAll();Note.noteItemListO.prepend(newItem);if(!isShare){Notebook.changeNotebookForNewNote(notebookId)}else{Share.changeNotebookForNewNote(notebookId)}}else{Note.noteItemListO.prepend(newItem)}Note.selectTarget($(tt('[noteId="?"]',note.NoteId)));$("#noteTitle").focus();Note.renderNote(note);Note.renderNoteContent(note);Note.curNoteId=note.NoteId;Notebook.incrNotebookNumberNotes(notebookId);Note.toggleWriteable()};Note.saveNote=function(e){var num=e.which?e.which:e.keyCode;if((e.ctrlKey||e.metaKey)&&num==83){Note.curChangedSaveIt();e.preventDefault();return false}else{}};Note.changeToNext=function(target){var $target=$(target);var next=$target.next();if(!next.length){var prev=$target.prev();if(prev.length){next=prev}else{Note.showEditorMask();return}}Note.changeNote(next.attr("noteId"))};Note.deleteNote=function(target,contextmenuItem,isShared){if($(target).hasClass("item-active")){Note.stopInterval();Note.curNoteId=null;Note.clearNoteInfo()}noteId=$(target).attr("noteId");if(!noteId){return}$(target).hide();var note=Note.cache[noteId];var url="/note/deleteNote";if(note.IsTrash){url="/note/deleteTrash"}else{Notebook.minusNotebookNumberNotes(note.NotebookId)}ajaxGet(url,{noteId:noteId,userId:note.UserId,isShared:isShared},function(ret){if(ret){Note.changeToNext(target);$(target).remove();if(note){Note.clearCacheByNotebookId(note.NotebookId);delete Note.cache[noteId]}showMsg("删除成功!",500)}else{$(target).show();showMsg("删除失败!",2e3)}})};Note.listNoteShareUserInfo=function(target){var noteId=$(target).attr("noteId");showDialogRemote("/share/listNoteShareUserInfo",{noteId:noteId})};Note.shareNote=function(target){var title=$(target).find(".item-title").text();showDialog("dialogShareNote",{title:getMsg("shareToFriends")+"-"+title});setTimeout(function(){$("#friendsEmail").focus()},500);var noteId=$(target).attr("noteId");shareNoteOrNotebook(noteId,true)};Note.listNoteContentHistories=function(){$("#leanoteDialog #modalTitle").html(getMsg("history"));$content=$("#leanoteDialog .modal-body");$content.html("");$("#leanoteDialog .modal-footer").html('<button type="button" class="btn btn-default" data-dismiss="modal">'+getMsg("close")+"</button>");options={};options.show=true;$("#leanoteDialog").modal(options);ajaxGet("/noteContentHistory/listHistories",{noteId:Note.curNoteId},function(re){if(!isArray(re)){$content.html(getMsg("noHistories"));return}var str="<p>"+getMsg("historiesNum")+'</p><div id="historyList"><table class="table table-hover">';note=Note.cache[Note.curNoteId];var s="div";if(note.IsMarkdown){s="pre"}for(i in re){var content=re[i];content.Ab=Note.genAbstract(content.Content,200);str+='<tr><td seq="'+i+'">#'+(i+1)+"<"+s+' class="each-content">'+content.Ab+"</"+s+'> <div class="btns">'+getMsg("datetime")+': <span class="label label-default">'+goNowToDatetime(content.UpdatedTime)+'</span> <button class="btn btn-default all">'+getMsg("unfold")+'</button> <button class="btn btn-primary back">'+getMsg("restoreFromThisVersion")+"</button></div></td></tr>"}str+="</table></div>";$content.html(str);$("#historyList .all").click(function(){$p=$(this).parent().parent();var seq=$p.attr("seq");var $c=$p.find(".each-content");var info=re[seq];if(!info.unfold){$(this).text(getMsg("fold"));$c.html(info.Content);info.unfold=true}else{$(this).text(getMsg("unfold"));$c.html(info.Ab);info.unfold=false}});$("#historyList .back").click(function(){$p=$(this).parent().parent();var seq=$p.attr("seq");if(confirm(getMsg("confirmBackup"))){Note.curChangedSaveIt();note=Note.cache[Note.curNoteId];setEditorContent(re[seq].Content,note.IsMarkdown);hideDialog()}})})};Note.showReadOnly=function(){Note.isReadOnly=true;$("#note").addClass("read-only")};Note.hideReadOnly=function(){Note.isReadOnly=false;$("#note").removeClass("read-only");$("#noteRead").hide()};Note.renderNoteReadOnly=function(note){Note.showReadOnly();$("#noteReadTitle").html(note.Title||getMsg("unTitled"));Tag.renderReadOnlyTags(note.Tags);$("#noteReadCreatedTime").html(goNowToDatetime(note.CreatedTime));$("#noteReadUpdatedTime").html(goNowToDatetime(note.UpdatedTime))};Note.renderNoteContentReadOnly=function(note){};Note.lastSearch=null;Note.lastKey=null;Note.lastSearchTime=new Date;Note.isOver2Seconds=false;Note.isSameSearch=function(key){var now=new Date;var duration=now.getTime()-Note.lastSearchTime.getTime();Note.isOver2Seconds=duration>2e3?true:false;if(!Note.lastKey||Note.lastKey!=key||duration>1e3){Note.lastKey=key;Note.lastSearchTime=now;return false}if(key==Note.lastKey){return true}Note.lastSearchTime=now;Note.lastKey=key;return false};Note.searchNote=function(){var val=$("#searchNoteInput").val();if(!val){Notebook.changeNotebook("0");return}if(Note.isSameSearch(val)){return}if(Note.lastSearch){Note.lastSearch.abort()}Note.curChangedSaveIt();Note.clearAll();showLoading();Note.lastSearch=$.post("/note/searchNote",{key:val},function(notes){hideLoading();if(notes){Note.lastSearch=null;Note.renderNotes(notes);if(!isEmpty(notes)){Note.changeNote(notes[0].NoteId,false)}}else{}})};Note.setNote2Blog=function(target){var noteId=$(target).attr("noteId");var note=Note.cache[noteId];var isBlog=true;if(note.IsBlog!=undefined){isBlog=!note.IsBlog}if(isBlog){$(target).find(".item-blog").show()}else{$(target).find(".item-blog").hide()}ajaxPost("/note/setNote2Blog",{noteId:noteId,isBlog:isBlog},function(ret){if(ret){Note.setNoteCache({NoteId:noteId,IsBlog:isBlog},false)}})};Note.setAllNoteBlogStatus=function(notebookId,isBlog){if(!notebookId){return}var notes=Note.getNotesByNotebookId(notebookId);if(!isArray(notes)){return}var len=notes.length;if(len==0){for(var i in Note.cache){if(Note.cache[i].NotebookId==notebookId){Note.cache[i].IsBlog=isBlog}}}else{for(var i=0;i<len;++i){notes[i].IsBlog=isBlog}}};Note.moveNote=function(target,data){var noteId=$(target).attr("noteId");var note=Note.cache[noteId];var notebookId=data.notebookId;if(!note.IsTrash&&note.NotebookId==notebookId){return}Notebook.incrNotebookNumberNotes(notebookId);if(!note.IsTrash){Notebook.minusNotebookNumberNotes(note.NotebookId)}ajaxGet("/note/moveNote",{noteId:noteId,notebookId:notebookId},function(ret){if(ret&&ret.NoteId){if(note.IsTrash){Note.changeToNext(target);$(target).remove();Note.clearCacheByNotebookId(notebookId)}else{if(!Notebook.curActiveNotebookIsAll()){Note.changeToNext(target);if($(target).hasClass("item-active")){Note.clearNoteInfo()}$(target).remove()}else{$(target).find(".note-notebook").html(Notebook.getNotebookTitle(notebookId))}Note.clearCacheByNotebookId(note.NotebookId);Note.clearCacheByNotebookId(notebookId)}Note.setNoteCache(ret)}})};Note.copyNote=function(target,data,isShared){var noteId=$(target).attr("noteId");var note=Note.cache[noteId];var notebookId=data.notebookId;if(note.IsTrash||note.NotebookId==notebookId){return}var url="/note/copyNote";var data={noteId:noteId,notebookId:notebookId};if(isShared){url="/note/copySharedNote";data.fromUserId=note.UserId}ajaxGet(url,data,function(ret){if(ret&&ret.NoteId){Note.clearCacheByNotebookId(notebookId);Note.setNoteCache(ret)}});Notebook.incrNotebookNumberNotes(notebookId)};Note.deleteNoteTag=function(item,tag){if(!item){return}for(var noteId in item){var note=Note.getNote(noteId);if(note){note.Tags=note.Tags||[];for(var i in note.Tags){if(note.Tags[i]==tag){note.Tags.splice(i,1);continue}}if(noteId==Note.curNoteId){Tag.renderTags(note.Tags)}}}};Note.readOnly=true;Note.toggleReadOnly=function(){if(LEA.em&&LEA.em.isWriting()){return Note.toggleWriteable()}var me=this;var note=me.getCurNote();var $editor=$("#editor");$editor.addClass("read-only").removeClass("all-tool");$("#editorContent").attr("contenteditable",false);$("#mdEditor").addClass("read-only");if(!note){return}if(note.IsMarkdown){$("#mdInfoToolbar .created-time").html(goNowToDatetime(note.CreatedTime));$("#mdInfoToolbar .updated-time").html(goNowToDatetime(note.UpdatedTime))}else{$("#infoToolbar .created-time").html(goNowToDatetime(note.CreatedTime));$("#infoToolbar .updated-time").html(goNowToDatetime(note.UpdatedTime))}if(note.readOnly){return}if(!note.IsMarkdown){$("#editorContent pre").each(function(){LeaAce.setAceReadOnly($(this),true)})}note.readOnly=true;Note.readOnly=true};Note.toggleWriteable=function(){var me=this;$("#editor").removeClass("read-only");$("#editorContent").attr("contenteditable",true);$("#mdEditor").removeClass("read-only");var note=me.getCurNote();if(!note){return}if(!note.readOnly){return}if(!note.IsMarkdown){$("#editorContent pre").each(function(){LeaAce.setAceReadOnly($(this),false)})}else{if(MD){MD.onResize()}}note.readOnly=false;Note.readOnly=false};Note.getContextNotebooks=function(notebooks){var moves=[];var copys=[];var copys2=[];for(var i in notebooks){var notebook=notebooks[i];var move={text:notebook.Title,notebookId:notebook.NotebookId,action:Note.moveNote};var copy={text:notebook.Title,notebookId:notebook.NotebookId,action:Note.copyNote};var copy2={text:notebook.Title,notebookId:notebook.NotebookId,action:Share.copySharedNote};if(!isEmpty(notebook.Subs)){var mc=Note.getContextNotebooks(notebook.Subs);move.items=mc[0];copy.items=mc[1];copy2.items=mc[2];move.type="group";move.width=150;copy.type="group";copy.width=150;copy2.type="group";copy2.width=150}moves.push(move);copys.push(copy);copys2.push(copy2)}return[moves,copys,copys2]};Note.contextmenu=null;Note.notebooksCopy=[];Note.initContextmenu=function(){var self=Note;if(Note.contextmenu){Note.contextmenu.destroy()}var notebooks=Notebook.everNotebooks;var mc=self.getContextNotebooks(notebooks);var notebooksMove=mc[0];var notebooksCopy=mc[1];self.notebooksCopy=mc[2];var noteListMenu={width:180,items:[{text:getMsg("shareToFriends"),alias:"shareToFriends",icon:"",faIcon:"fa-share-square-o",action:Note.listNoteShareUserInfo},{type:"splitLine"},{text:getMsg("publicAsBlog"),alias:"set2Blog",faIcon:"fa-bold",action:Note.setNote2Blog},{text:getMsg("cancelPublic"),alias:"unset2Blog",faIcon:"fa-undo",action:Note.setNote2Blog},{type:"splitLine"},{text:getMsg("delete"),icon:"",faIcon:"fa-trash-o",action:Note.deleteNote},{text:getMsg("move"),alias:"move",faIcon:"fa-arrow-right",type:"group",width:180,items:notebooksMove},{text:getMsg("copy"),alias:"copy",icon:"",faIcon:"fa-copy",type:"group",width:180,items:notebooksCopy}],onShow:applyrule,onContextMenu:beforeContextMenu,parent:"#noteItemList",children:".item-my"};function menuAction(target){showDialog("dialogUpdateNotebook",{title:"修改笔记本",postShow:function(){}})}function applyrule(menu){var noteId=$(this).attr("noteId");var note=Note.cache[noteId];if(!note){return}var items=[];if(note.IsTrash){items.push("shareToFriends");items.push("shareStatus");items.push("unset2Blog");items.push("set2Blog");items.push("copy")}else{if(!note.IsBlog){items.push("unset2Blog")}else{items.push("set2Blog")}var notebookTitle=Notebook.getNotebookTitle(note.NotebookId);items.push("move."+notebookTitle);items.push("copy."+notebookTitle)}menu.applyrule({name:"target..",disable:true,items:items})}function beforeContextMenu(){return this.id!="target3"}Note.contextmenu=$("#noteItemList .item-my").contextmenu(noteListMenu)};var Attach={loadedNoteAttachs:{},attachsMap:{},init:function(){var self=this;$("#showAttach").click(function(){self.renderAttachs(Note.curNoteId)});self.attachListO.click(function(e){e.stopPropagation()});self.attachListO.on("click",".delete-attach",function(e){e.stopPropagation();var attachId=$(this).closest("li").data("id");var t=this;if(confirm("Are you sure to delete it ?")){$(t).button("loading");ajaxPost("/attach/deleteAttach",{attachId:attachId},function(re){$(t).button("reset");if(reIsOk(re)){self.deleteAttach(attachId)}else{alert(re.Msg)}})}});self.attachListO.on("click",".download-attach",function(e){e.stopPropagation();var attachId=$(this).closest("li").data("id");window.open(UrlPrefix+"/attach/download?attachId="+attachId)});self.downloadAllBtnO.click(function(){window.open(UrlPrefix+"/attach/downloadAll?noteId="+Note.curNoteId)});self.attachListO.on("click",".link-attach",function(e){e.stopPropagation();var attachId=$(this).closest("li").data("id");var attach=self.attachsMap[attachId];var src=UrlPrefix+"/attach/download?attachId="+attachId;if(LEA.isMarkdownEditor()&&MD){MD.insertLink(src,attach.Title)}else{tinymce.activeEditor.insertContent('<a target="_blank" href="'+src+'">'+attach.Title+"</a>")}});self.linkAllBtnO.on("click",function(e){e.stopPropagation();var note=Note.getCurNote();if(!note){return}var src=UrlPrefix+"/attach/downloadAll?noteId="+Note.curNoteId;var title=note.Title?note.Title+".tar.gz":"all.tar.gz";if(LEA.isMarkdownEditor()&&MD){MD.insertLink(src,title)}else{tinymce.activeEditor.insertContent('<a target="_blank" href="'+src+'">'+title+"</a>")}})},attachListO:$("#attachList"),attachNumO:$("#attachNum"),attachDropdownO:$("#attachDropdown"),downloadAllBtnO:$("#downloadAllBtn"),linkAllBtnO:$("#linkAllBtn"),clearNoteAttachNum:function(){var self=this;self.attachNumO.html("").hide()},renderNoteAttachNum:function(noteId,needHide){var self=this;var note=Note.getNote(noteId);if(note.AttachNum){self.attachNumO.html("("+note.AttachNum+")").show();self.downloadAllBtnO.show();self.linkAllBtnO.show()}else{self.attachNumO.hide();self.downloadAllBtnO.hide();self.linkAllBtnO.hide()}if(needHide){self.attachDropdownO.removeClass("open")}},_renderAttachs:function(attachs){var self=this;var html="";var attachNum=attachs.length;for(var i=0;i<attachNum;++i){var each=attachs[i];html+='<li class="clearfix" data-id="'+each.AttachId+'">'+'<div class="attach-title">'+each.Title+"</div>"+'<div class="attach-process"> '+'	  <button class="btn btn-sm btn-warning delete-attach" data-loading-text="..."><i class="fa fa-trash-o"></i></button> '+'	  <button type="button" class="btn btn-sm btn-primary download-attach"><i class="fa fa-download"></i></button> '+'	  <button type="button" class="btn btn-sm btn-default link-attach" title="Insert link into content"><i class="fa fa-link"></i></button> '+"</div>"+"</li>";self.attachsMap[each.AttachId]=each}self.attachListO.html(html);var note=Note.getCurNote();if(note){note.AttachNum=attachNum;self.renderNoteAttachNum(note.NoteId,false)}},_bookmark:null,renderAttachs:function(noteId){var self=this;if(self.loadedNoteAttachs[noteId]){self._renderAttachs(self.loadedNoteAttachs[noteId]);return}self.attachListO.html('<li class="loading"><img src="/images/loading-24.gif"/></li>');ajaxGet("/attach/getAttachs",{noteId:noteId},function(ret){var list=[];if(ret.Ok){list=ret.List;if(!list){list=[]}}self.loadedNoteAttachs[noteId]=list;self._renderAttachs(list)})},addAttach:function(attachInfo){var self=this;if(!self.loadedNoteAttachs[attachInfo.NoteId]){self.loadedNoteAttachs[attachInfo.NoteId]=[]}self.loadedNoteAttachs[attachInfo.NoteId].push(attachInfo);self.renderAttachs(attachInfo.NoteId)},deleteAttach:function(attachId){var self=this;var noteId=Note.curNoteId;var attachs=self.loadedNoteAttachs[noteId];for(var i=0;i<attachs.length;++i){if(attachs[i].AttachId==attachId){attachs.splice(i,1);break}}self.renderAttachs(noteId)},downloadAttach:function(fileId){var self=this},downloadAll:function(){}};$(function(){Attach.init();$("#noteItemList").on("mouseenter",".item",function(event){if(LEA.isIpad||LEA.isIphone){$(this).trigger("click")}});$("#noteItemList").on("click",".item",function(event){event.stopPropagation();var noteId=$(this).attr("noteId");Mobile.changeNote(noteId);if(!noteId){return}if(Note.curNoteId!=noteId){Note.changeNoteForPjax(noteId,true,false)}});$("#editorContent, #wmd-input, #noteTitle").on("keyup input",function(){Note.curNoteIsDirtied()});$("#newNoteBtn, #editorMask .note").click(function(){var notebookId=$("#curNotebookForNewNote").attr("notebookId");Note.newNote(notebookId)});$("#newNoteMarkdownBtn, #editorMask .markdown").click(function(){var notebookId=$("#curNotebookForNewNote").attr("notebookId");Note.newNote(notebookId,false,"",true)});$("#notebookNavForNewNote").on("click","li div",function(){var notebookId=$(this).attr("notebookId");if($(this).hasClass("new-note-right")){Note.newNote(notebookId,false,"",true)}else{Note.newNote(notebookId)}});$("#searchNotebookForAdd").click(function(e){e.stopPropagation()});$("#searchNotebookForAdd").keyup(function(){var key=$(this).val();Notebook.searchNotebookForAddNote(key)});$("#searchNotebookForList").keyup(function(){var key=$(this).val();Notebook.searchNotebookForList(key)});$("#searchNoteInput").on("keydown",function(e){var theEvent=e;if(theEvent.keyCode==13||theEvent.keyCode==108){theEvent.preventDefault();Note.searchNote();return false}});$("#contentHistory").click(function(){Note.listNoteContentHistories()});$("#saveBtn").click(function(){Note.curChangedSaveIt(true)});$("#noteItemList").on("click",".item-blog",function(e){e.preventDefault();e.stopPropagation();var noteId=$(this).parent().attr("noteId");window.open("/blog/view/"+noteId)});$("#noteItemList").on("click",".item-my .item-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();Note.contextmenu.showMenu(e,$p)});$(".toolbar-update").click(function(){Note.toggleWriteable()})});Note.startInterval();Tag.classes={"蓝色":"label label-blue","红色":"label label-red","绿色":"label label-green","黄色":"label label-yellow",blue:"label label-blue",red:"label label-red",green:"label label-green",yellow:"label label-yellow"};Tag.mapCn2En={"蓝色":"blue","红色":"red","绿色":"green","黄色":"yellow"};Tag.mapEn2Cn={blue:"蓝色",red:"红色",green:"绿色",yellow:"黄色"};Tag.t=$("#tags");Tag.getTags=function(){var tags=[];Tag.t.children().each(function(){var text=$(this).data("tag");text=Tag.mapCn2En[text]||text;tags.push(text)});return tags};Tag.clearTags=function(){Tag.t.html("")};Tag.renderTags=function(tags){Tag.t.html("");if(isEmpty(tags)){return}for(var i=0;i<tags.length;++i){var tag=tags[i];Tag.appendTag(tag)}};function revertTagStatus(){$("#addTagTrigger").show();$("#addTagInput").hide()}function hideTagList(event){$("#tagDropdown").removeClass("open");if(event){event.stopPropagation()}}function showTagList(event){$("#tagDropdown").addClass("open");if(event){event.stopPropagation()}}Tag.renderReadOnlyTags=function(tags){$("#noteReadTags").html("");if(isEmpty(tags)||tags.length==1&&tags[0]==""){$("#noteReadTags").html(getMsg("noTag"))}var i=true;function getNextDefaultClasses(){if(i){return"label label-default";i=false}else{i=true;return"label label-info"}}for(var i in tags){var text=tags[i];text=Tag.mapEn2Cn[text]||text;var classes=Tag.classes[text];if(!classes){classes=getNextDefaultClasses()}tag=tt('<span class="?">?</span>',classes,text);$("#noteReadTags").append(tag)}};Tag.appendTag=function(tag,save){var isColor=false;var classes,text;if(typeof tag=="object"){classes=tag.classes;text=tag.text;if(!text){return}}else{tag=$.trim(tag);text=tag;if(!text){return}var classes=Tag.classes[text];if(classes){isColor=true}else{classes="label label-default"}}var rawText=text;if(LEA.locale=="zh"){text=Tag.mapEn2Cn[text]||text;rawText=Tag.mapCn2En[rawText]||rawText}tag=tt('<span class="?" data-tag="?">?<i title="'+getMsg("delete")+'">X</i></span>',classes,text,text);var isExists=false;$("#tags").children().each(function(){if(isColor){var tagHtml=$("<div></div>").append($(this).clone()).html();if(tagHtml==tag){$(this).remove();isExists=true}}else if(text+"X"==$(this).text()){$(this).remove();isExists=true}});$("#tags").append(tag);hideTagList();if(!isColor){reRenderTags()}if(save){Note.curNoteIsDirtied();if(!isExists){Note.curChangedSaveIt(true,function(){ajaxPost("/tag/updateTag",{tag:rawText},function(ret){if(reIsOk(ret)){Tag.addTagNav(ret.Item)}})})}}};function reRenderTags(){var defautClasses=["label label-default","label label-info"];var i=0;$("#tags").children().each(function(){var thisClasses=$(this).attr("class");if(thisClasses=="label label-default"||thisClasses=="label label-info"){$(this).removeClass(thisClasses).addClass(defautClasses[i%2]);i++}})}Tag.removeTag=function($target){var tag=$target.data("tag");$target.remove();reRenderTags();if(LEA.locale=="zh"){tag=Tag.mapCn2En[tag]||tag}Note.curChangedSaveIt(true,function(){ajaxPost("/tag/updateTag",{tag:tag},function(ret){if(reIsOk(ret)){Tag.addTagNav(ret.Item)}})})};Tag.tags=[];Tag.renderTagNav=function(tags){var me=this;tags=tags||[];Tag.tags=tags;$("#tagNav").html("");for(var i in tags){var noteTag=tags[i];var tag=noteTag.Tag;var text=tag;if(LEA.locale=="zh"){var text=Tag.mapEn2Cn[tag]||text}var classes=Tag.classes[tag]||"label label-default";$("#tagNav").append(tt('<li data-tag="?"><a> <span class="?">?</span> <span class="tag-delete">X</span></li>',tag,classes,text))}};Tag.addTagNav=function(newTag){var me=this;for(var i in me.tags){var noteTag=me.tags[i];if(noteTag.Tag==newTag.Tag){me.tags.splice(i,1);break}}me.tags.unshift(newTag);me.renderTagNav(me.tags)};$(function(){$("#addTagTrigger").click(function(){$(this).hide();$("#addTagInput").show().focus().val("")});$("#addTagInput").click(function(event){showTagList(event)});$("#addTagInput").blur(function(){var val=$(this).val();if(val){Tag.appendTag(val,true)}return;$("#addTagTrigger").show();$("#addTagInput").hide()});$("#addTagInput").keydown(function(e){if(e.keyCode==13){hideTagList();if($("#addTagInput").val()){$(this).trigger("blur");$("#addTagTrigger").trigger("click")}else{$(this).trigger("blur")}}});$("#tagColor li").click(function(event){var a;if($(this).attr("role")){a=$(this).find("span")}else{a=$(this)}Tag.appendTag({classes:a.attr("class"),text:a.text()},true)});$("#tags").on("click","i",function(){Tag.removeTag($(this).parent())});function deleteTag(){$li=$(this).closest("li");var tag=$.trim($li.data("tag"));if(confirm("Are you sure ?")){ajaxPost("/tag/deleteTag",{tag:tag},function(re){if(reIsOk(re)){var item=re.Item;Note.deleteNoteTag(item,tag);$li.remove()}})}}function searchTag(){var $li=$(this).closest("li");var tag=$.trim($li.data("tag"));Note.curChangedSaveIt();Note.clearAll();$("#tagSearch").html($li.html()).show();$("#tagSearch .tag-delete").remove();showLoading();ajaxGet("/note/searchNoteByTags",{tags:[tag]},function(notes){hideLoading();if(notes){Note.renderNotes(notes);if(!isEmpty(notes)){Note.changeNote(notes[0].NoteId)}}})}$("#myTag .folderBody").on("click","li .label",searchTag);$("#myTag .folderBody").on("click","li .tag-delete",deleteTag)});Notebook.curNotebookId="";Notebook.cache={};Notebook.notebooks=[];Notebook.notebookNavForListNote="";Notebook.notebookNavForNewNote="";Notebook.setCache=function(notebook){var notebookId=notebook.NotebookId;if(!notebookId){return}if(!Notebook.cache[notebookId]){Notebook.cache[notebookId]={}}$.extend(Notebook.cache[notebookId],notebook)};Notebook.getCurNotebookId=function(){return Notebook.curNotebookId};Notebook.getCurNotebook=function(){return Notebook.cache[Notebook.curNotebookId]};Notebook._updateNotebookNumberNotes=function(notebookId,n){var self=this;var notebook=self.getNotebook(notebookId);if(!notebook){return}notebook.NumberNotes+=n;if(notebook.NumberNotes<0){notebook.NumberNotes=0}$("#numberNotes_"+notebookId).html(notebook.NumberNotes)};Notebook.incrNotebookNumberNotes=function(notebookId){var self=this;self._updateNotebookNumberNotes(notebookId,1)};Notebook.minusNotebookNumberNotes=function(notebookId){var self=this;self._updateNotebookNumberNotes(notebookId,-1)};Notebook.getNotebook=function(notebookId){return Notebook.cache[notebookId]};Notebook.getNotebookTitle=function(notebookId){var notebook=Notebook.cache[notebookId];if(notebook){return notebook.Title}else{return"未知"}};Notebook.getTreeSetting=function(isSearch,isShare){var noSearch=!isSearch;var self=this;function addDiyDom(treeId,treeNode){var spaceWidth=5;var switchObj=$("#"+treeId+" #"+treeNode.tId+"_switch"),icoObj=$("#"+treeId+" #"+treeNode.tId+"_ico");switchObj.remove();icoObj.before(switchObj);if(!isShare){if(!Notebook.isAllNotebookId(treeNode.NotebookId)&&!Notebook.isTrashNotebookId(treeNode.NotebookId)){icoObj.after($('<span class="notebook-number-notes" id="numberNotes_'+treeNode.NotebookId+'">'+(treeNode.NumberNotes||0)+"</span>"));icoObj.after($('<span class="fa notebook-setting" title="setting"></span>'))}}else{if(!Share.isDefaultNotebookId(treeNode.NotebookId)){icoObj.after($('<span class="fa notebook-setting" title="setting"></span>'))}}if(treeNode.level>1){var spaceStr="<span style='display: inline-block;width:"+spaceWidth*treeNode.level+"px'></span>";switchObj.before(spaceStr)}}function beforeDrag(treeId,treeNodes){for(var i=0,l=treeNodes.length;i<l;i++){if(treeNodes[i].drag===false){return false}}return true}function beforeDrop(treeId,treeNodes,targetNode,moveType){return targetNode?targetNode.drop!==false:true}function onDrop(e,treeId,treeNodes,targetNode,moveType){var treeNode=treeNodes[0];if(!targetNode){return}var parentNode;var treeObj=self.tree;var ajaxData={curNotebookId:treeNode.NotebookId};if(moveType=="inner"){parentNode=targetNode}else{parentNode=targetNode.getParentNode()}if(!parentNode){var nodes=treeObj.getNodes()}else{ajaxData.parentNotebookId=parentNode.NotebookId;var nextLevel=parentNode.level+1;function filter(node){return node.level==nextLevel}var nodes=treeObj.getNodesByFilter(filter,false,parentNode)}ajaxData.siblings=[];for(var i in nodes){var notebookId=nodes[i].NotebookId;if(!Notebook.isAllNotebookId(notebookId)&&!Notebook.isTrashNotebookId(notebookId)){ajaxData.siblings.push(notebookId)}}ajaxPost("/notebook/dragNotebooks",{data:JSON.stringify(ajaxData)});setTimeout(function(){Notebook.changeNav()},100)}if(!isShare){var onClick=function(e,treeId,treeNode){var notebookId=treeNode.NotebookId;Notebook.changeNotebook(notebookId)};var onDblClick=function(e){var notebookId=$(e.target).attr("notebookId");if(!Notebook.isAllNotebookId(notebookId)&&!Notebook.isTrashNotebookId(notebookId)){self.updateNotebookTitle(e.target)}}}else{var onClick=function(e,treeId,treeNode){var notebookId=treeNode.NotebookId;var fromUserId=$(e.target).closest(".friend-notebooks").attr("fromUserId");Share.changeNotebook(fromUserId,notebookId)};var onDblClick=null}var setting={view:{showLine:false,showIcon:false,selectedMulti:false,dblClickExpand:false,addDiyDom:addDiyDom},data:{key:{name:"Title",children:"Subs"}},edit:{enable:true,showRemoveBtn:false,showRenameBtn:false,drag:{isMove:noSearch,prev:noSearch,inner:noSearch,next:noSearch}},callback:{beforeDrag:beforeDrag,beforeDrop:beforeDrop,onDrop:onDrop,onClick:onClick,onDblClick:onDblClick,beforeRename:function(treeId,treeNode,newName,isCancel){if(newName==""){if(treeNode.IsNew){self.tree.removeNode(treeNode);return true}return false}if(treeNode.Title==newName){return true}if(treeNode.IsNew){var parentNode=treeNode.getParentNode();var parentNotebookId=parentNode?parentNode.NotebookId:"";self.doAddNotebook(treeNode.NotebookId,newName,parentNotebookId)}else{self.doUpdateNotebookTitle(treeNode.NotebookId,newName)}return true}}};if(isSearch){}return setting};Notebook.allNotebookId="0";Notebook.trashNotebookId="-1";Notebook.curNotebookIsTrashOrAll=function(){return Notebook.curNotebookId==Notebook.trashNotebookId||Notebook.curNotebookId==Notebook.allNotebookId};Notebook.renderNotebooks=function(notebooks){var self=this;if(!notebooks||typeof notebooks!="object"||notebooks.length<0){notebooks=[]}for(var i=0,len=notebooks.length;i<len;++i){var notebook=notebooks[i];notebook.Title=trimTitle(notebook.Title)}notebooks=[{NotebookId:Notebook.allNotebookId,Title:getMsg("all"),drop:false,drag:false}].concat(notebooks);notebooks.push({NotebookId:Notebook.trashNotebookId,Title:getMsg("trash"),drop:false,drag:false});Notebook.notebooks=notebooks;self.tree=$.fn.zTree.init($("#notebookList"),self.getTreeSetting(),notebooks);var $notebookList=$("#notebookList");$notebookList.hover(function(){if(!$(this).hasClass("showIcon")){$(this).addClass("showIcon")}},function(){$(this).removeClass("showIcon")});if(!isEmpty(notebooks)){Notebook.curNotebookId=notebooks[0].NotebookId;self.cacheAllNotebooks(notebooks)}Notebook.renderNav();Notebook.changeNotebookNavForNewNote(notebooks[0].NotebookId)};Notebook.cacheAllNotebooks=function(notebooks){var self=this;for(var i in notebooks){var notebook=notebooks[i];Notebook.cache[notebook.NotebookId]=notebook;if(!isEmpty(notebook.Subs)){self.cacheAllNotebooks(notebook.Subs)}}};Notebook.expandNotebookTo=function(notebookId,userId){var me=this;var selected=false;var tree=me.tree;if(userId){tree=Share.trees[userId]}if(!tree){return}var curNode=tree.getNodeByTId(notebookId);if(!curNode){return}while(true){var pNode=curNode.getParentNode();if(pNode){tree.expandNode(pNode,true);if(!selected){Notebook.changeNotebookNav(notebookId);selected=true}curNode=pNode}else{if(!selected){Notebook.changeNotebookNav(notebookId)}break}}};Notebook.renderNav=function(nav){var self=this;self.changeNav()};Notebook.searchNotebookForAddNote=function(key){var self=this;if(key){var notebooks=self.tree.getNodesByParamFuzzy("Title",key);notebooks=notebooks||[];var notebooks2=[];for(var i in notebooks){var notebookId=notebooks[i].NotebookId;if(!self.isAllNotebookId(notebookId)&&!self.isTrashNotebookId(notebookId)){notebooks2.push(notebooks[i])}}if(isEmpty(notebooks2)){$("#notebookNavForNewNote").html("")}else{$("#notebookNavForNewNote").html(self.getChangedNotebooks(notebooks2))}}else{$("#notebookNavForNewNote").html(self.everNavForNewNote)}};Notebook.searchNotebookForList=function(key){var self=this;var $search=$("#notebookListForSearch");var $notebookList=$("#notebookList");if(key){$search.show();$notebookList.hide();var notebooks=self.tree.getNodesByParamFuzzy("Title",key);log("search");log(notebooks);if(isEmpty(notebooks)){$search.html("")}else{var setting=self.getTreeSetting(true);self.tree2=$.fn.zTree.init($search,setting,notebooks)}}else{self.tree2=null;$search.hide();$notebookList.show();$("#notebookNavForNewNote").html(self.everNavForNewNote)}};Notebook.getChangedNotebooks=function(notebooks){var self=this;var navForNewNote="";var len=notebooks.length;for(var i=0;i<len;++i){var notebook=notebooks[i];var classes="";if(!isEmpty(notebook.Subs)){classes="dropdown-submenu"}var eachForNew=tt('<li role="presentation" class="clearfix ?"><div class="new-note-left pull-left" title="为该笔记本新建笔记" href="#" notebookId="?">?</div><div title="为该笔记本新建markdown笔记" class="new-note-right pull-left" notebookId="?">M</div>',classes,notebook.NotebookId,notebook.Title,notebook.NotebookId);if(!isEmpty(notebook.Subs)){eachForNew+="<ul class='dropdown-menu'>";eachForNew+=self.getChangedNotebooks(notebook.Subs);eachForNew+="</ul>"}eachForNew+="</li>";navForNewNote+=eachForNew}return navForNewNote};Notebook.everNavForNewNote="";Notebook.everNotebooks=[];Notebook.changeNav=function(){var self=Notebook;var notebooks=Notebook.tree.getNodes();var pureNotebooks=notebooks.slice(1,-1);var html=self.getChangedNotebooks(pureNotebooks);self.everNavForNewNote=html;self.everNotebooks=pureNotebooks;$("#notebookNavForNewNote").html(html);var t1=(new Date).getTime();Note.initContextmenu();Share.initContextmenu(Note.notebooksCopy);var t2=(new Date).getTime();log(t2-t1)};Notebook.renderShareNotebooks=function(sharedUserInfos,shareNotebooks){if(isEmpty(sharedUserInfos)){return}if(!shareNotebooks||typeof shareNotebooks!="object"||shareNotebooks.length<0){return}var $shareNotebooks=$("#shareNotebooks");var user2ShareNotebooks={};for(var i in shareNotebooks){var userNotebooks=shareNotebooks[i];user2ShareNotebooks[userNotebooks.UserId]=userNotebooks}for(var i in sharedUserInfos){var userInfo=sharedUserInfos[i];var userNotebooks=user2ShareNotebooks[userInfo.UserId]||{ShareNotebooks:[]};userNotebooks.ShareNotebooks=[{NotebookId:"-2",Title:"默认共享"}].concat(userNotebooks.ShareNotebooks);var username=userInfo.Username||userInfo.Email;var header=tt('<div class="folderNote closed"><div class="folderHeader"><a><h1 title="? 的共享"><i class="fa fa-angle-right"></i>?</h1></a></div>',username,username);var body='<ul class="folderBody">';for(var j in userNotebooks.ShareNotebooks){var notebook=userNotebooks.ShareNotebooks[j];body+=tt('<li><a notebookId="?">?</a></li>',notebook.NotebookId,notebook.Title)}body+="</ul>";$shareNotebooks.append(header+body+"</div>")}};Notebook.selectNotebook=function(target){$(".notebook-item").removeClass("curSelectedNode");$(target).addClass("curSelectedNode")};Notebook.changeNotebookNavForNewNote=function(notebookId,title){if(!notebookId){var notebook=Notebook.notebooks[0];notebookId=notebook.NotebookId;title=notebook.Title}if(!title){var notebook=Notebook.cache[0];title=notebook.Title}if(!Notebook.isAllNotebookId(notebookId)&&!Notebook.isTrashNotebookId(notebookId)){$("#curNotebookForNewNote").html(title).attr("notebookId",notebookId)}else if(!$("#curNotebookForNewNote").attr("notebookId")){if(Notebook.notebooks.length>2){var notebook=Notebook.notebooks[1];notebookId=notebook.NotebookId;title=notebook.Title;Notebook.changeNotebookNavForNewNote(notebookId,title)}}};Notebook.toggleToMyNav=function(userId,notebookId){$("#sharedNotebookNavForListNav").hide();$("#myNotebookNavForListNav").show();$("#newMyNote").show();$("#newSharedNote").hide();$("#tagSearch").hide()};Notebook.changeNotebookNav=function(notebookId){Notebook.curNotebookId=notebookId;Notebook.toggleToMyNav();Notebook.selectNotebook($(tt('#notebook [notebookId="?"]',notebookId)));var notebook=Notebook.cache[notebookId];if(!notebook){return}$("#curNotebookForListNote").html(notebook.Title);Notebook.changeNotebookNavForNewNote(notebookId,notebook.Title)};Notebook.isAllNotebookId=function(notebookId){return notebookId==Notebook.allNotebookId};Notebook.isTrashNotebookId=function(notebookId){return notebookId==Notebook.trashNotebookId};Notebook.curActiveNotebookIsAll=function(){return Notebook.isAllNotebookId($("#notebookList .active").attr("notebookId"))};Notebook.changeNotebookSeq=1;Notebook.changeNotebook=function(notebookId,callback){var me=this;Notebook.changeNotebookNav(notebookId);Notebook.curNotebookId=notebookId;Note.curChangedSaveIt();Note.clearAll();var url="/note/listNotes/";var param={notebookId:notebookId};if(Notebook.isTrashNotebookId(notebookId)){url="/note/listTrashNotes";param={}}else if(Notebook.isAllNotebookId(notebookId)){param={};cacheNotes=Note.getNotesByNotebookId();if(!isEmpty(cacheNotes)){if(callback){callback(cacheNotes)}else{Note.renderNotesAndFirstOneContent(cacheNotes)}return}}else{cacheNotes=Note.getNotesByNotebookId(notebookId);var notebook=Notebook.cache[notebookId];var len=cacheNotes?cacheNotes.length:0;if(len==notebook.NumberNotes){if(callback){callback(cacheNotes)}else{Note.renderNotesAndFirstOneContent(cacheNotes)}return}else{Note.clearCacheByNotebookId(notebookId);log("数量不一致")}}me.showNoteAndEditorLoading();me.changeNotebookSeq++;(function(seq){ajaxGet(url,param,function(cacheNotes){if(seq!=me.changeNotebookSeq){log("notebook changed too fast!");log(cacheNotes);return}if(callback){callback(cacheNotes)}else{Note.renderNotesAndFirstOneContent(cacheNotes)}me.hideNoteAndEditorLoading()})})(me.changeNotebookSeq)};Notebook.showNoteAndEditorLoading=function(){$("#noteAndEditorMask").show()};Notebook.hideNoteAndEditorLoading=function(){$("#noteAndEditorMask").hide()};Notebook.isCurNotebook=function(notebookId){return $(tt('#notebookList [notebookId="?"], #shareNotebooks [notebookId="?"]',notebookId,notebookId)).attr("class")=="active"};Notebook.changeNotebookForNewNote=function(notebookId){if(Notebook.isTrashNotebookId(notebookId)||Notebook.isAllNotebookId(notebookId)){return}Notebook.changeNotebookNav(notebookId,true);Notebook.curNotebookId=notebookId;var url="/note/listNotes/";var param={notebookId:notebookId};ajaxGet(url,param,function(ret){Note.renderNotes(ret,true)})};Notebook.listNotebookShareUserInfo=function(target){var notebookId=$(target).attr("notebookId");showDialogRemote("/share/listNotebookShareUserInfo",{notebookId:notebookId})};Notebook.shareNotebooks=function(target){var title=$(target).text();showDialog("dialogShareNote",{title:"分享笔记本给好友-"+title});setTimeout(function(){$("#friendsEmail").focus()},500);var notebookId=$(target).attr("notebookId");shareNoteOrNotebook(notebookId,false)};Notebook.setNotebook2Blog=function(target){var notebookId=$(target).attr("notebookId");var notebook=Notebook.cache[notebookId];var isBlog=true;if(notebook.IsBlog!=undefined){isBlog=!notebook.IsBlog}if(Notebook.curNotebookId==notebookId){if(isBlog){$("#noteList .item-blog").show()}else{$("#noteList .item-blog").hide()}}else if(Notebook.curNotebookId==Notebook.allNotebookId){$("#noteItemList .item").each(function(){var noteId=$(this).attr("noteId");var note=Note.cache[noteId];if(note.NotebookId==notebookId){if(isBlog)$(this).find(".item-blog").show();else $(this).find(".item-blog").hide()}})}ajaxPost("/notebook/setNotebook2Blog",{notebookId:notebookId,isBlog:isBlog},function(ret){if(ret){Note.setAllNoteBlogStatus(notebookId,isBlog);Notebook.setCache({NotebookId:notebookId,IsBlog:isBlog})}})};Notebook.updateNotebookTitle=function(target){var self=Notebook;var notebookId=$(target).attr("notebookId");if(self.tree2){self.tree2.editName(self.tree2.getNodeByTId(notebookId))}else{self.tree.editName(self.tree.getNodeByTId(notebookId))}};Notebook.doUpdateNotebookTitle=function(notebookId,newTitle){var self=Notebook;ajaxPost("/notebook/updateNotebookTitle",{notebookId:notebookId,title:newTitle},function(ret){Notebook.cache[notebookId].Title=newTitle;Notebook.changeNav();if(self.tree2){var notebook=self.tree.getNodeByTId(notebookId);notebook.Title=newTitle;self.tree.updateNode(notebook)}})};Notebook.addNotebookSeq=1;Notebook.addNotebook=function(){var self=Notebook;if($("#myNotebooks").hasClass("closed")){$("#myNotebooks .folderHeader").trigger("click")}self.tree.addNodes(null,{Title:"",NotebookId:getObjectId(),IsNew:true},true,true)};Notebook.doAddNotebook=function(notebookId,title,parentNotebookId){var self=Notebook;ajaxPost("/notebook/addNotebook",{notebookId:notebookId,title:title,parentNotebookId:parentNotebookId},function(ret){if(ret.NotebookId){Notebook.cache[ret.NotebookId]=ret;var notebook=self.tree.getNodeByTId(notebookId);$.extend(notebook,ret);notebook.IsNew=false;Notebook.changeNotebook(notebookId);Notebook.changeNav()}})};Notebook.addChildNotebook=function(target){var self=Notebook;if($("#myNotebooks").hasClass("closed")){$("#myNotebooks .folderHeader").trigger("click")}var notebookId=$(target).attr("notebookId");self.tree.addNodes(self.tree.getNodeByTId(notebookId),{Title:"",NotebookId:getObjectId(),IsNew:true},false,true)};Notebook.deleteNotebook=function(target){var self=Notebook;var notebookId=$(target).attr("notebookId");if(!notebookId){return}ajaxGet("/notebook/deleteNotebook",{notebookId:notebookId},function(ret){if(ret.Ok){self.tree.removeNode(self.tree.getNodeByTId(notebookId));if(self.tree2){self.tree2.removeNode(self.tree2.getNodeByTId(notebookId))}delete Notebook.cache[notebookId];Notebook.changeNav()}else{alert(ret.Msg)}})};$(function(){$("#minNotebookList").on("click","li",function(){var notebookId=$(this).find("a").attr("notebookId");Notebook.changeNotebook(notebookId)});var notebookListMenu={width:180,items:[{text:getMsg("shareToFriends"),alias:"shareToFriends",icon:"",faIcon:"fa-share-square-o",action:Notebook.listNotebookShareUserInfo},{type:"splitLine"},{text:getMsg("publicAsBlog"),alias:"set2Blog",faIcon:"fa-bold",action:Notebook.setNotebook2Blog},{text:getMsg("cancelPublic"),alias:"unset2Blog",faIcon:"fa-undo",action:Notebook.setNotebook2Blog},{type:"splitLine"},{text:getMsg("addChildNotebook"),faIcon:"fa-sitemap",action:Notebook.addChildNotebook},{text:getMsg("rename"),faIcon:"fa-pencil",action:Notebook.updateNotebookTitle},{text:getMsg("delete"),icon:"",alias:"delete",faIcon:"fa-trash-o",action:Notebook.deleteNotebook}],onShow:applyrule,onContextMenu:beforeContextMenu,parent:"#notebookList ",children:"li a"};var notebookListMenu2={width:180,items:[{text:getMsg("shareToFriends"),alias:"shareToFriends",icon:"",faIcon:"fa-share-square-o",action:Notebook.listNotebookShareUserInfo},{type:"splitLine"},{text:getMsg("publicAsBlog"),alias:"set2Blog",faIcon:"fa-bold",action:Notebook.setNotebook2Blog},{text:getMsg("cancelPublic"),alias:"unset2Blog",faIcon:"fa-undo",action:Notebook.setNotebook2Blog},{type:"splitLine"},{text:getMsg("rename"),icon:"",action:Notebook.updateNotebookTitle},{text:getMsg("delete"),icon:"",alias:"delete",faIcon:"fa-trash-o",action:Notebook.deleteNotebook}],onShow:applyrule,onContextMenu:beforeContextMenu,parent:"#notebookListForSearch ",children:"li a"};function applyrule(menu){var notebookId=$(this).attr("notebookId");var notebook=Notebook.cache[notebookId];if(!notebook){return}var items=[];if(!notebook.IsBlog){items.push("unset2Blog")}else{items.push("set2Blog")}if(Note.notebookHasNotes(notebookId)){items.push("delete")}menu.applyrule({name:"target2",disable:true,items:items})}function beforeContextMenu(){var notebookId=$(this).attr("notebookId");return!Notebook.isTrashNotebookId(notebookId)&&!Notebook.isAllNotebookId(notebookId)}Notebook.contextmenu=$("#notebookList li a").contextmenu(notebookListMenu);Notebook.contextmenuSearch=$("#notebookListForSearch li a").contextmenu(notebookListMenu2);$("#addNotebookPlus").click(function(e){e.stopPropagation();Notebook.addNotebook()});$("#notebookList").on("click",".notebook-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();Notebook.contextmenu.showMenu(e,$p)});$("#notebookListForSearch").on("click",".notebook-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();Notebook.contextmenuSearch.showMenu(e,$p)})});Share.defaultNotebookId="share0";Share.defaultNotebookTitle=getMsg("defaulthhare");Share.sharedUserInfos={};Share.userNavs={};Share.notebookCache={};Share.cache={};Share.dialogIsNote=true;Share.setCache=function(note){if(!note||!note.NoteId){return}Share.cache[note.NoteId]=note};Share.getNotebooksForNew=function(userId,notebooks){var self=this;var navForNewNote="";var len=notebooks.length;for(var i=0;i<len;++i){var notebook=notebooks[i];notebook.IsShared=true;notebook.UserId=userId;self.notebookCache[notebook.NotebookId]=notebook;Notebook.cache[notebook.NotebookId]=notebook;var classes="";var subs=false;if(!isEmpty(notebook.Subs)){log(11);log(notebook.Subs);var subs=self.getNotebooksForNew(userId,notebook.Subs);if(subs){classes="dropdown-submenu"}}var eachForNew="";if(notebook.Perm){var eachForNew=tt('<li role="presentation" class="clearfix ?" userId="?" notebookId="?"><div class="new-note-left pull-left" title="为该笔记本新建笔记" href="#">?</div><div title="为该笔记本新建markdown笔记" class="new-note-right pull-left">M</div>',classes,userId,notebook.NotebookId,notebook.Title);if(subs){eachForNew+="<ul class='dropdown-menu'>";eachForNew+=subs;eachForNew+="</ul>"}eachForNew+="</li>"}navForNewNote+=eachForNew}return navForNewNote};Share.trees={};Share.renderShareNotebooks=function(sharedUserInfos,shareNotebooks){var self=Share;if(isEmpty(sharedUserInfos)){return}if(!shareNotebooks||typeof shareNotebooks!="object"||shareNotebooks.length<0){shareNotebooks={}}var $shareNotebooks=$("#shareNotebooks");for(var i in sharedUserInfos){var userInfo=sharedUserInfos[i];var userNotebooksPre=shareNotebooks[userInfo.UserId]||[];userNotebooks=[{NotebookId:self.defaultNotebookId,Title:Share.defaultNotebookTitle}].concat(userNotebooksPre);self.notebookCache[self.defaultNotebookId]=userNotebooks[0];var username=userInfo.Username||userInfo.Email;userInfo.Username=username;Share.sharedUserInfos[userInfo.UserId]=userInfo;var userId=userInfo.UserId;var header=tt('<li class="each-user"><div class="friend-header" fromUserId="?"><i class="fa fa-angle-down"></i><span>?</span> <span class="fa notebook-setting" title="setting"></span> </div>',userInfo.UserId,username);var friendId="friendContainer_"+userId;var body='<ul class="friend-notebooks ztree" id="'+friendId+'" fromUserId="'+userId+'"></ul>';$shareNotebooks.append(header+body+"</li>");self.trees[userId]=$.fn.zTree.init($("#"+friendId),Notebook.getTreeSetting(true,true),userNotebooks);self.userNavs[userId]={forNew:self.getNotebooksForNew(userId,userNotebooksPre)};log(self.userNavs)}$(".friend-notebooks").hover(function(){if(!$(this).hasClass("showIcon")){$(this).addClass("showIcon")}},function(){$(this).removeClass("showIcon")});$(".friend-header i").click(function(){var $this=$(this);var $tree=$(this).parent().next();if($tree.is(":hidden")){$tree.slideDown("fast");$this.removeClass("fa-angle-right fa-angle-down").addClass("fa-angle-down")}else{$tree.slideUp("fast");$this.removeClass("fa-angle-right fa-angle-down").addClass("fa-angle-right")}});var shareNotebookMenu={width:180,items:[{text:getMsg("deleteSharedNotebook"),icon:"",faIcon:"fa-trash-o",action:Share.deleteShareNotebook}],onShow:applyrule,onContextMenu:beforeContextMenu,parent:"#shareNotebooks",children:".notebook-item"};function applyrule(menu){return}function beforeContextMenu(){var notebookId=$(this).attr("notebookId");return!Share.isDefaultNotebookId(notebookId)}var menuNotebooks=$("#shareNotebooks").contextmenu(shareNotebookMenu);var shareUserMenu={width:180,items:[{text:getMsg("deleteAllShared"),icon:"",faIcon:"fa-trash-o",action:Share.deleteUserShareNoteAndNotebook}],parent:"#shareNotebooks",children:".friend-header"};var menuUser=$("#shareNotebooks").contextmenu(shareUserMenu);$(".friend-header").on("click",".notebook-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();menuUser.showMenu(e,$p)});$("#shareNotebooks .notebook-item").on("click",".notebook-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();menuNotebooks.showMenu(e,$p)})};Share.isDefaultNotebookId=function(notebookId){return Share.defaultNotebookId==notebookId};Share.toggleToSharedNav=function(userId,notebookId){var self=this;$("#curNotebookForListNote").html(Share.notebookCache[notebookId].Title+"("+Share.sharedUserInfos[userId].Username+")");var forNew=Share.userNavs[userId].forNew;if(forNew){$("#notebookNavForNewSharedNote").html(forNew);var curNotebookId="";var curNotebookTitle="";if(Share.notebookCache[notebookId].Perm){curNotebookId=notebookId;curNotebookTitle=Share.notebookCache[notebookId].Title}else{var $f=$("#notebookNavForNewSharedNote li").eq(0);curNotebookId=$f.attr("notebookId");curNotebookTitle=$f.find(".new-note-left").text()}$("#curNotebookForNewSharedNote").html(curNotebookTitle+"("+Share.sharedUserInfos[userId].Username+")");$("#curNotebookForNewSharedNote").attr("notebookId",curNotebookId);$("#curNotebookForNewSharedNote").attr("userId",userId);$("#newSharedNote").show();$("#newMyNote").hide()}else{$("#newMyNote").show();$("#newSharedNote").hide()}$("#tagSearch").hide()};Share.firstRenderShareNote=function(ownerUserId,notebookId,noteId){$("#myShareNotebooks .folderHeader").trigger("click");Notebook.expandNotebookTo(notebookId,ownerUserId);Share.changeNotebook(ownerUserId,notebookId,function(notes){Note.renderNotes(notes);Note.changeNoteForPjax(noteId,false,false)})};Share.changeNotebook=function(userId,notebookId,callback){var me=this;Notebook.curNotebookId=notebookId;var $t=$(tt('#friendContainer_? a[notebookId="?"]',userId,notebookId));if($t.length==0){Notebook.selectNotebook($(tt('#friendContainer_? a[notebookId="?"]',userId,me.defaultNotebookId)));notebookId=me.defaultNotebookId}else{Notebook.selectNotebook($t)}Share.toggleToSharedNav(userId,notebookId);Note.curChangedSaveIt();Note.clearAll();var url="/share/listShareNotes";var param={userId:userId};if(!Share.isDefaultNotebookId(notebookId)){param.notebookId=notebookId}ajaxGet(url,param,function(ret){if(param.notebookId){}if(callback){callback(ret)}else{Note.renderNotes(ret,false,true);if(!isEmpty(ret)){Note.changeNoteForPjax(ret[0].NoteId,true,false)}else{}}})};Share.hasUpdatePerm=function(noteId){var note=Share.cache[noteId];if(!note){note=Note.getNote(noteId)}if(!note||!note.Perm){return false}return true};Share.deleteShareNotebook=function(target){if(confirm("Are you sure to delete it?")){var notebookId=$(target).attr("notebookId");var fromUserId=$(target).closest(".friend-notebooks").attr("fromUserId");ajaxGet("/share/DeleteShareNotebookBySharedUser",{notebookId:notebookId,fromUserId:fromUserId},function(ret){if(ret){$(target).parent().remove()}})}};Share.deleteShareNote=function(target){var noteId=$(target).attr("noteId");var fromUserId=$(target).attr("fromUserId");ajaxGet("/share/DeleteShareNoteBySharedUser",{noteId:noteId,fromUserId:fromUserId},function(ret){if(ret){$(target).remove()}})};Share.deleteUserShareNoteAndNotebook=function(target){if(confirm("Are you sure to delete all shared notebooks and notes?")){var fromUserId=$(target).attr("fromUserId");ajaxGet("/share/deleteUserShareNoteAndNotebook",{fromUserId:fromUserId},function(ret){if(ret){$(target).parent().remove()}})}};Share.changeNotebookForNewNote=function(notebookId){Notebook.selectNotebook($(tt('#shareNotebooks [notebookId="?"]',notebookId)));var userId=Share.notebookCache[notebookId].UserId;Share.toggleToSharedNav(userId,notebookId);var url="/share/listShareNotes";var param={userId:userId,notebookId:notebookId};ajaxGet(url,param,function(ret){Note.renderNotes(ret,true,true)})};Share.deleteSharedNote=function(target,contextmenuItem){Note.deleteNote(target,contextmenuItem,true)};Share.copySharedNote=function(target,contextmenuItem){Note.copyNote(target,contextmenuItem,true)};Share.contextmenu=null;Share.initContextmenu=function(notebooksCopy){if(Share.contextmenu){Share.contextmenu.destroy()}var noteListMenu={width:180,items:[{text:getMsg("copyToMyNotebook"),alias:"copy",faIcon:"fa-copy",type:"group",width:180,items:notebooksCopy},{type:"splitLine"},{text:getMsg("delete"),alias:"delete",icon:"",faIcon:"fa-trash-o",action:Share.deleteSharedNote}],onShow:applyrule,parent:"#noteItemList",children:".item-shared"};function applyrule(menu){var noteId=$(this).attr("noteId");var note=Share.cache[noteId];if(!note){return}var items=[];if(!(note.Perm&&note.CreatedUserId==UserInfo.UserId)){items.push("delete")}menu.applyrule({name:"target...",disable:true,items:items})}Share.contextmenu=$("#noteItemList .item-shared").contextmenu(noteListMenu)};$(function(){$("#noteItemList").on("click",".item-shared .item-setting",function(e){e.preventDefault();e.stopPropagation();var $p=$(this).parent();Share.contextmenu.showMenu(e,$p)});$("#newSharedNoteBtn").click(function(){var notebookId=$("#curNotebookForNewSharedNote").attr("notebookId");var userId=$("#curNotebookForNewSharedNote").attr("userId");Note.newNote(notebookId,true,userId)});$("#newShareNoteMarkdownBtn").click(function(){var notebookId=$("#curNotebookForNewSharedNote").attr("notebookId");var userId=$("#curNotebookForNewSharedNote").attr("userId");Note.newNote(notebookId,true,userId,true)});$("#notebookNavForNewSharedNote").on("click","li div",function(){var notebookId=$(this).parent().attr("notebookId");var userId=$(this).parent().attr("userId");if($(this).text()=="M"){Note.newNote(notebookId,true,userId,true)}else{Note.newNote(notebookId,true,userId)}});$("#leanoteDialogRemote").on("click",".change-perm",function(){var self=this;var perm=$(this).attr("perm");var noteOrNotebookId=$(this).attr("noteOrNotebookId");var toUserId=$(this).attr("toUserId");var toHtml=getMsg("writable");var toPerm="1";if(perm=="1"){toHtml=getMsg("readOnly");toPerm="0"}var url="/share/updateShareNotebookPerm";var param={perm:toPerm,toUserId:toUserId};if(Share.dialogIsNote){url="/share/updateShareNotePerm";param.noteId=noteOrNotebookId}else{param.notebookId=noteOrNotebookId}ajaxGet(url,param,function(ret){if(ret){$(self).html(toHtml);$(self).attr("perm",toPerm)}})});$("#leanoteDialogRemote").on("click",".delete-share",function(){var self=this;var noteOrNotebookId=$(this).attr("noteOrNotebookId");var toUserId=$(this).attr("toUserId");var url="/share/deleteShareNotebook";var param={toUserId:toUserId};if(Share.dialogIsNote){url="/share/deleteShareNote";param.noteId=noteOrNotebookId}else{param.notebookId=noteOrNotebookId}ajaxGet(url,param,function(ret){if(ret){$(self).parent().parent().remove()}})});var seq=1;$("#leanoteDialogRemote").on("click","#addShareNotebookBtn",function(){seq++;var tpl='<tr id="tr'+seq+'"><td>#</td><td><input id="friendsEmail" type="text" class="form-control" style="width: 200px" placeholder="'+getMsg("friendEmail")+'"/></td>';tpl+='<td><label for="readPerm'+seq+'"><input type="radio" name="perm'+seq+'" checked="checked" value="0" id="readPerm'+seq+'"> '+getMsg("readOnly")+"</label>";tpl+=' <label for="writePerm'+seq+'"><input type="radio" name="perm'+seq+'" value="1" id="writePerm'+seq+'"> '+getMsg("writable")+"</label></td>";tpl+='<td><button class="btn btn-success" onclick="addShareNoteOrNotebook('+seq+')">'+getMsg("share")+"</button>";tpl+=' <button class="btn btn-warning" onclick="deleteShareNoteOrNotebook('+seq+')">'+getMsg("delete")+"</button>";tpl+="</td></tr>";$("#shareNotebookTable tbody").prepend(tpl);$("#tr"+seq+" #friendsEmail").focus()});$("#registerEmailBtn").click(function(){var content=$("#emailContent").val();var toEmail=$("#toEmail").val();if(!content){showAlert("#registerEmailMsg",getMsg("emailBodyRequired"),"danger");return}post("/user/sendRegisterEmail",{content:content,toEmail:toEmail},function(ret){showAlert("#registerEmailMsg",getMsg("sendSuccess"),"success");hideDialog2("#sendRegisterEmailDialog",1e3)},this)})});function addShareNoteOrNotebook(trSeq){var trId="#tr"+trSeq;var id=Share.dialogNoteOrNotebookId;var emails=isEmailFromInput(trId+" #friendsEmail","#shareMsg",getMsg("inputFriendEmail"));if(!emails){return}var shareNotePerm=$(trId+' input[name="perm'+trSeq+'"]:checked').val()||0;var perm=shareNotePerm;var url="/share/addShareNote";var data={noteId:id,emails:[emails],perm:shareNotePerm};if(!Share.dialogIsNote){url="/share/addShareNotebook";data={notebookId:id,emails:[emails],perm:shareNotePerm}}hideAlert("#shareMsg");post(url,data,function(ret){var ret=ret[emails];if(ret){if(ret.Ok){var tpl=tt("<td>?</td>","#");tpl+=tt("<td>?</td>",emails);tpl+=tt('<td><a href="#" noteOrNotebookId="?" perm="?" toUserId="?" title="'+getMsg("clickToChangePermission")+'" class="btn btn-default change-perm">?</a></td>',id,perm,ret.Id,!perm||perm=="0"?getMsg("readOnly"):getMsg("writable"));tpl+=tt('<td><a href="#" noteOrNotebookId="?" toUserId="?" class="btn btn-warning delete-share">'+getMsg("delete")+"</a></td>",id,ret.Id);$(trId).html(tpl)}else{var shareUrl=UrlPrefix+"/register?iu="+UserInfo.Username;showAlert("#shareMsg",getMsg("friendNotExits",[getMsg("app"),'<input style="background: none;border: 1px solid #ccc;width: 300px;padding: 3px;border-radius: 3px;outline: none;" onclick="$(this).focus().select()" type="text" value="'+shareUrl+'" />'])+"</a> <br /> "+getMsg("sendInviteEmailToYourFriend")+', <a href="#" onclick="sendRegisterEmail(\''+emails+"')\">"+getMsg("send"),"warning")}}},trId+" .btn-success")}function sendRegisterEmail(email){showDialog2("#sendRegisterEmailDialog",{postShow:function(){$("#emailContent").val(getMsg("inviteEmailBody",[UserInfo.Username,getMsg("app")]));setTimeout(function(){$("#emailContent").focus()},500);$("#toEmail").val(email)}})}function deleteShareNoteOrNotebook(trSeq){$("#tr"+trSeq).remove()}var ObjectId=function(){var increment=0;var pid=Math.floor(Math.random()*32767);var machine=Math.floor(Math.random()*16777216);if(typeof localStorage!="undefined"){var mongoMachineId=parseInt(localStorage["mongoMachineId"]);if(mongoMachineId>=0&&mongoMachineId<=16777215){machine=Math.floor(localStorage["mongoMachineId"])}localStorage["mongoMachineId"]=machine;document.cookie="mongoMachineId="+machine+";expires=Tue, 19 Jan 2038 05:00:00 GMT"}else{var cookieList=document.cookie.split("; ");for(var i in cookieList){var cookie=cookieList[i].split("=");if(cookie[0]=="mongoMachineId"&&cookie[1]>=0&&cookie[1]<=16777215){machine=cookie[1];break}}document.cookie="mongoMachineId="+machine+";expires=Tue, 19 Jan 2038 05:00:00 GMT"}function ObjId(){if(!(this instanceof ObjectId)){return new ObjectId(arguments[0],arguments[1],arguments[2],arguments[3]).toString()}if(typeof arguments[0]=="object"){this.timestamp=arguments[0].timestamp;this.machine=arguments[0].machine;this.pid=arguments[0].pid;this.increment=arguments[0].increment}else if(typeof arguments[0]=="string"&&arguments[0].length==24){this.timestamp=Number("0x"+arguments[0].substr(0,8)),this.machine=Number("0x"+arguments[0].substr(8,6)),this.pid=Number("0x"+arguments[0].substr(14,4)),this.increment=Number("0x"+arguments[0].substr(18,6))}else if(arguments.length==4&&arguments[0]!=null){this.timestamp=arguments[0];this.machine=arguments[1];this.pid=arguments[2];this.increment=arguments[3]}else{this.timestamp=Math.floor((new Date).valueOf()/1e3);this.machine=machine;this.pid=pid;this.increment=increment++;if(increment>16777215){increment=0}}}return ObjId}();ObjectId.prototype.getDate=function(){return new Date(this.timestamp*1e3)};ObjectId.prototype.toArray=function(){var strOid=this.toString();var array=[];var i;for(i=0;i<12;i++){array[i]=parseInt(strOid.slice(i*2,i*2+2),16)}return array};ObjectId.prototype.toString=function(){var timestamp=this.timestamp.toString(16);var machine=this.machine.toString(16);var pid=this.pid.toString(16);var increment=this.increment.toString(16);return"00000000".substr(0,8-timestamp.length)+timestamp+"000000".substr(0,6-machine.length)+machine+"0000".substr(0,4-pid.length)+pid+"000000".substr(0,6-increment.length)+increment};